问题
ValueError: invalid \x escape:
File "SConstruct", line 49:
execfile("hosts.cfg")
I'm completely stumped with this one guys...
If I print right before line 49, I can see the output. On the very first line of "hosts.cfg" I put a second print statement which is never executed.
回答1:
Even on Windows, forward slashes should work for directory names, so you could standardize on those:
"libpath" : [".", "../xlib", "../tools", "../info"],
Or use raw strings, as @Adam Rosenfield already said in a comment:
"libpath" : [r".", r"..\xlib", r"..\tools", r"..\info"],
I think both of the above solutions are better than doubling all the backslashes, and loads better than just doubling backslashes for directory names that start with 'x'.
回答2:
"libpath" : [".", "..\xlib", "..\tools", "..\info"],
This was the problematic line inside hosts.cfg, don't know why Python kept complaining about the execfile line instead of the one inside the file I was calling.
I changed to:
\\xlib and it's working now.
来源:https://stackoverflow.com/questions/10559654/valueerror-invalid-x-escape