Skip to content Skip to sidebar Skip to footer

How To Write \t To File Using Python

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

Solution 1:

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

Solution 2:

... 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'

Post a Comment for "How To Write \t To File Using Python"