Ullsokk
Ullsokk

Reputation: 717

input filepath and pass to string literal

I am working on a script that takes user input in the form of a filepath for a SAS data set. To get the filepath to work when developing the program I use

data= r'//filepath/file.sas7bdat'

But I want now to pass the filepath from user input like this:

path = input("Filepath: ")

To be used in

df = pd.read_sas(data, format = 'sas7bdat', encoding="cp1252")

But I cant figure out how to pass the filepath to the use the literal r' ', something like this

data=r'path'

Upvotes: 1

Views: 155

Answers (1)

blhsing
blhsing

Reputation: 106455

The raw string is only useful when you hard-code a string literal with backslashes in it. Since you now want path to be from the user's input, there is no need to use a raw string at all, and you can use path as it is returned by input() directly:

df = pd.read_sas(path, format = 'sas7bdat', encoding="cp1252")

Upvotes: 1

Related Questions