python - Using a raw string with os.walk() -
i'm trying os.walk() work in program i'm working on, keep getting error: valueerror: invalid \x escape
from looking around online, i've seen error can arise not using raw string. however, still keep getting error...
import os path = r'd:\data\tracking\' root, dirs, files in os.walk(path): print root print dirs print files
anyone have idea of can differently make work?
try using \\
prevent last backslash escaping quote after it.
>>> path = r'd:\data\tracking\' file "<input>", line 1 path = r'd:\data\tracking\' ^ syntaxerror: eol while scanning string literal >>> path = r'd:\data\tracking\\' >>> print(path) d:\data\tracking\\
you can without raw string exact string want:
>>> path = 'd:\\data\tracking\\' >>> print(path) d:\data\tracking\
Comments
Post a Comment