Home > database >  Using "r" for escape sequence when file in Julia
Using "r" for escape sequence when file in Julia

Time:11-10

On the Python using r front of the file path, can deal with escape sequence such as :

   df = pd.read_csv(r"D:\datasets\42133.csv")

However on Julia, the below code returns, MethodError: no method matching joinpath(::Regex)

file_path = r"D:\datasets\42133.csv"
df = DataFrame(CSV.File(file_path))

I checked this, and know that I can chage \ to \\ or /. But wondering that why Julia does not allowed to use r"String"? Also is there something like r"String" on Julia?

CodePudding user response:

You are looking for raw"..." string.

julia> raw"D:\datasets\42133.csv"
"D:\\datasets\\42133.csv"

In Julia, r"..." strings create a Regex object.

  • Related