2

I build one web and user can enter directory path in form.

My program will extract the path and write into one file.

My question is when the path include some special word such as \t \n, the program can't write file correctly.

For example: C:\abc\test will become C:\abc[TAB]est

How can I change the string into other type like raw string and write file correctly ?

Thank you for your reply.

Jimmy Lin
  • 1,481
  • 6
  • 27
  • 44
  • 1
    check this http://stackoverflow.com/questions/12576418/how-to-include-backslash-and-quotes-in-python-strings/12576426#12576426 – avasal Feb 06 '13 at 07:47

2 Answers2

2

Use r'C:\abc\test' or 'C:\\abc\\test' when you enter your strings

Yevgen Yampolskiy
  • 7,022
  • 3
  • 26
  • 23
1

... user can enter directory path in form.

...

My question is when the path include some special word such as \t \n, the program can't write file correctly.

Uh, no. Python is perfectly capable of distinguishing between '\t' and '\\t' unless you are doing something to confuse it.

>>> raw_input()
<Ctrl-V><Tab>
'\t'
>>> raw_input()
\t
'\\t'
Community
  • 1
  • 1
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358