A backslash followed by a number in python lines

I ran into a problem in Python when dealing with backslashes, followed by numbers inside a string. I am using Windows OS environment.

This becomes especially annoying when you have numbers at the beginning of a name in a directory.

Example: "P:\70_parseFile\80_FileDir\60_FA_050"

It was a revelation for me that you can create special characters if you do "\ 1", "\ 2", "\ 3" ... and so on. Surprisingly, I have to ask how to do this, or what other string function exists that does not have this special function?

Thank you all!

+5
source share
2 answers

You have two options:

  • Backslash with backslash:

    "P:\\70_parseFile\\80_FileDir\\60_FA_050"
    
  • , " "

    r"P:\70_parseFile\80_FileDir\60_FA_050"
    
+11

\1, \2 .. . , , .

re.escape(), .

re.escape()

; , .

+2

All Articles