“EOL while scanning single-quoted string”? (backslash in string)

前端 未结 5 1691
心在旅途
心在旅途 2020-12-06 08:05
import os
xp1 = \"\\Documents and Settings\\\"
xp2 = os.getenv(\"USERNAME\")
print xp1+xp2

Gives me error

 File \"1.py\", line 2 
x         


        
5条回答
  •  孤城傲影
    2020-12-06 08:51

    Additionally to the blackslash problem, don't join paths with the "+" operator -- use os.path.join instead.

    Also, construct the path to a user's home directory like that is likely to fail on new versions of Windows. There are API functions for that in pywin32.

提交回复
热议问题