reg exp and octal notation

Lucas Branca nospam at freeworld.fr
Fri Mar 5 11:33:29 EST 2004


Great!
It's just what I was looking for.
(...and I read it in "what's new" this morning ......
... "boing boing" with my head now ... :)  )

Thank you very much



"Jeff Epler" <jepler at unpythonic.net> ha scritto nel messaggio
news:mailman.24.1078501788.19534.python-list at python.org...
> If you have a string and want to perform backslash-substitution on it,
> use python2.3's "string_escape" codec.
>
> Two examples:
>
> >>> s = "\\n"
> >>> s
> '\\n'
> >>> s.decode("string_escape")
> '\n'
>
> >>> "\x30"
> '0'
> >>> "\\x30"
> '\\x30'
> >>> "\\x30".decode("string_escape")
> '0'
>
> You can remove the trailing newline this way:
>     if s.endswith("\n"): s = s[:-1]
>
> Jeff
>





More information about the Python-list mailing list