I have this enviroment variable: VAR=C:\\Users\\User
but how can I prevent python giving this "SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \\UXXXXXXXX escape
error when I try:
import os
os.environ["VAR"]
without needing to change the variable in Command line
The unicode error comes from the "\\U". So you can also change your
VAR=C:\Users\User
to
VAR=C:\\Users\\User
so that Python recognizes the dashes as literal dashes.
Maybe the reason are the dashs. Did you try:
Try VAR=C:/Users/User
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.