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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -