Two problems with backslashes

whr whrauser at erols.com
Wed Jul 4 17:11:00 CEST 2001


Here is a clue:

>>> path = 'e:\test\test.txt'
>>> path
'e:\test\test.txt'
>>> print path
e:   est   est.txt

And another one:

>>> path.replace('\t','/t')
'e:/test/test.txt'
>>>

Walt

'\t' is a tab character

"Gustaf Liljegren" <gustafl at algonet.se> wrote in message
news:Xns90D4A141E71CDgustaflalgonetse at 194.213.69.148...
> I have two problems with backslashes in DOS path strings:
>
> >>> path = 'e:\test\test.txt'
> >>> path.replace('\\', '/')
> 'e:\test\test.txt'
>
> Expected:
>
> 'e:/test/test.txt'
>
> Also, split() doesn't like backslashes:
>
> >>> paths = 'e:\test\file1.txt e:\test\file2.txt'
> >>> paths.split()
> ['e:', 'est', 'ile1.txt', 'e:', 'est', 'ile2.txt']
>
> Expected:
>
> ['e:\test\file1.txt', 'e:\test\file2.txt']
>
> Alternative ways would be much appreciated.
>
> Regards,
>
> Gustaf Liljegren





More information about the Python-list mailing list