-1

When I try to use

    print variable + "\filename"

the slash isn't recognized as a string character, however if I were to do

    print variable + "\Filename"

capitalizing the first letter proceeding the slash... then the slash is recognized as a string character

The only thing I was able to find online is that in some cases a \ with a letter preceding it may be used to end a string of raw characters but I don't understand this.

So my question is why does this happen? And more importantly what is a way around this or a fix for this. Thank you.

Michael rimboim
  • 11
  • 1
  • 1
  • 1

1 Answers1

2

You need to mark it as raw with the prefix r. Like this: print variable + r"\filename" Or alternatively you can escape it using a backslash print variable + "\\filename"

ech0
  • 512
  • 4
  • 14