0

I am very new to Python and am getting this small problem. I am using Python 3.3

There is a variable I declared in my code

file_name = "resource\email\ham\6.txt"

However, when I look for the variable, it appends additional numbers

>>file_name
'resource\\email\\ham\x06.txt'

Is there a reason why it behaves as so? If not, how do I remove those additional characters? Also, why are they there?

bryan.blackbee
  • 1,934
  • 4
  • 32
  • 46

1 Answers1

3

Use r raw string:

file_name = r"resource\email\ham\6.txt"

Double \:

  file_name = "resource\\email\\ham\\6.txt"

Or /:

file_name = "resource/email/ham/6.txt"

\ has a special meaning in python, it is used to escape characters.

Padraic Cunningham
  • 176,452
  • 29
  • 245
  • 321