Quantcast
Channel: User David Z - Stack Overflow
Viewing all articles
Browse latest Browse all 48

Answer by David Z for Why does the filepath become invalid when in reality it is completely valid?

$
0
0

Python interprets \t in a string as an escape code for a tab character. However, \l has no such special interpretation so it gets interpreted as a backslash plus l.

To fix this, I suggest using raw strings, i.e. prefix the string with an r:

filepath = r"G:\learning python\page view time series\trum.csv"

Alternatively, you could escape the backslashes, but that gets a bit tedious:

filepath = "G:\\learning python\\page view time series\\trum.csv"

Strictly speaking, the only one you really need to escape in this case is the one before t, but it's probably more trouble than it's worth (and also possibly confusing) to escape some backslashes but not others.


Viewing all articles
Browse latest Browse all 48

Trending Articles