ValueError: invalid \x escape:

陌路散爱 提交于 2019-12-20 07:39:55

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!