reg exp and octal notation
Ruud de Jong
ruud.de.jong at consunet.nl
Fri Mar 5 09:52:09 EST 2004
Lucas Branca schreef:
> Could someone explain me the difference between the results below?
>
> ## $cat octals.txt
> ## \006\034abc
>
> import re
>
> a= "\006\034abc"
> preg= re.compile(r'([\0-\377]*)')
> res = preg.search(a)
> print res.groups()
>
> loader = open('./octals.txt', 'r')
> b = loader.readline()
Look at the value of b at this point, you'll see:
>>> b
'\\006\\034abc\n'
In other words, the backslashes are seen as literal backslashes.
readline() does no evaluation of the string, it just copies the
characters.
Regards,
Ruud
> preg= re.compile(r'([\0-\377]*)')
> res = preg.search(b)
> print res.groups()
>
>
> RESULTS
>
> ('\x06\x1cabc',)
>
> ('\\006\\034abc\n',)
>
>
> Many thanks
> Lucas
>
>
More information about the Python-list
mailing list