Two problems with backslashes

Michael Ströder michael at stroeder.com
Wed Jul 4 17:02:45 CEST 2001


Gustaf Liljegren wrote:
> 
> I have two problems with backslashes in DOS path strings:
> 
> >>> path = 'e:\test\test.txt'

I guess that's already the error. You did not specify a correct DOS
path name. \t is a tab character. Hence your problems with
string.split().

Try instead:
>>> path = 'e:\\test\\test.txt'
>>> path
'e:\\test\\test.txt'
>>> print path
e:\test\test.txt
>>> # or as an alternative
>>> path = r'e:\test\test.txt'
>>> path
'e:\\test\\test.txt'
>>> print path
e:\test\test.txt

> Alternative ways would be much appreciated.

You should dig into module os.path.

Ciao, Michael.



More information about the Python-list mailing list