user3333824
user3333824

Reputation: 23

Backslashes and forwardslashes getting mixed up in Python

While programming in Python, I've ran into a problem.

This line of code:

kickoff.write("rsyncbins\rsync --progress --recursive --delete --exclude rsyncbins/ --exclude etc/ --exclude logs/ --exclude screenshots/ --exclude uninstall.exe rsync://denver-1.download.toontownrewritten.com/ttr_win32/ .")

This goes into a batch file, but python thinks the \ and / are file paths and it screws everything up. How can I fix this?

Upvotes: 0

Views: 74

Answers (1)

jminuscula
jminuscula

Reputation: 552

I think your problem is that you are introducing the \r special character in the string. The backslash is used to escape characters, so if you want to actually write "\r", you have two options:

  • escape the escape character. ie: rsyncbins\\rsync
  • tell python to not escape anything. ie: kickoff.write(r"rsyncbins\rsync...")

There is no reason for python to be confused about slashes, don't worry!

Upvotes: 5

Related Questions