Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using "r" for escape sequence when file in Julia

Tags:

string

julia

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?

like image 334
Chanhee Avatar asked Nov 09 '21 08:11

Chanhee


People also ask

How do you escape from Julia?

All escape sequences in Julia start with '\'. \" is an escape sequence that is used to double-quote inside the formatted version of a string. \n is an escape sequence that is used to shift the bits of string onto the next line. \t is an escape sequence that is used to insert space up to the next tab stop.

How do you know if strings are equal in Julia?

The cmp() is an inbuilt function in julia which is used to return 0 if the both specified strings are having the same length and the character at each index is the same in both strings, return -1 if a is a prefix of b, or if a comes before b in alphabetical order and return 1 if b is a prefix of a, or if b comes before ...


1 Answers

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

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

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

like image 166
fredrikekre Avatar answered Sep 18 '22 00:09

fredrikekre