Simple Problem

Jp Calderone exarkun at divmod.com
Sun Jul 24 21:33:48 EDT 2005


On 24 Jul 2005 18:14:13 -0700, ncf <nothingcanfulfill at gmail.com> wrote:
>I know I've seen this somewhere before, but does anyone know what the
>function to escape a string is? (i.e., encoding newline to "\n" and a
>chr(254) to "\xfe") (and visa-versa)
>
>Thanks for helping my ignorance :P

    Python 2.4.1 (#2, Mar 30 2005, 21:51:10) 
    [GCC 3.3.5 (Debian 1:3.3.5-8ubuntu2)] on linux2
    Type "help", "copyright", "credits" or "license" for more information.
    >>> '\n\xfe'.encode('string-escape')
    '\\n\\xfe'
    >>> '\\n\\xfe'.decode('string-escape')
    '\n\xfe'
    >>> 

  Introduced in Python 2.3

  Jp



More information about the Python-list mailing list