简体   繁体   中英

Is there a way to prevent Python from recognizing escape characters?

Code:

import os
filename = "cp.lnk"
lnk = "shortcuts\cmd_shortcuts\" + filename
os.system(lnk)

And that gives me this error, I'm assuming, because it recognizes escape quotes in the variable:

'shortcuts' is not recognized as an internal or external command, operable program or batch file.

I then tried:

import os
filename = "cp.lnk"
lnk = r"shortcuts\cmd_shortcuts\" + filename
os.system(lnk)

It game me the same error. How can I fix this?

Thank you!

Edit: Sorry my question was so bad ):

Pretty sure that should fix it but don't quote me on that.

import os
filename = "cp.lnk"
lnk = r"shortcuts\\cmd_shortcuts\\" + filename
os.system(lnk)
import os
filename = "cp.lnk"
lnk = "shortcuts\\cmd_shortcuts\\" + filename
os.system(lnk)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM