[Tutor] Raw string
john at fouhy.net
Mon Jul 21 00:34:20 CEST 2008
On 21/07/2008, Neven Goršić <neven.gorsic at gmail.com> wrote:
> >>> s='e:\mm tests\1. exp files\5.MOC-1012.exp'
> >>> os.path.split(s)
> ('e:\\', 'mm tests\x01. exp files\x05.MOC-1012.exp')
> The problem is that \1 and \5 is wrongly understood.
Yup, that's not surprising.
> I know that
> everything works fine if I put raw string prefix r in front of string
> which I put between "":
> but I can not do it that because I have already read path string
> and it is now stored in variable s.
Are you sure?
If I create a file tmp which contains just that string:
### tmp ### this line not part of file ###
e:\mm tests\1. exp files\5.MOC-1012.exp
### end tmp ###
and I read it in:
>>> f = open('tmp')
>>> s = f.read()
Then I get:
'e:\\mm tests\\1. exp files\\5.MOC-1012.exp\n'
which, apart from the newline on the end, looks like exactly what you
want. If this isn't working for you, can you show what is going
More information about the Tutor