Backslash substitutions

Discussion in 'Python' started by Vivien Mallet, Sep 29, 2004.

  1. Hello,

    How would you perform backslash substitution in a string, just like the
    Python parser does?

    Example:
    ---
    >>> s = "\\n"
    >>> print s

    \n
    >>> print ???(s)



    >>>

    ---
    where '???' is a function that I wasn't able to find.

    Just in case, another example:
    ---
    >>> s = "\\\\A\\tB"
    >>> print s

    \\A\tB
    >>> print ???(s)

    \A B
    >>>

    ---

    Thank you.
     
    Vivien Mallet, Sep 29, 2004
    #1
    1. Advertising

  2. Vivien Mallet

    Peter Otten Guest

    Vivien Mallet wrote:

    > How would you perform backslash substitution in a string, just like the
    > Python parser does?


    >>> "\\\\A\\tB".decode("string_escape")

    '\\A\tB'
    >>> _.encode("string_escape") # back again

    '\\\\A\\tB'

    Peter
     
    Peter Otten, Sep 29, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RJGraham
    Replies:
    6
    Views:
    506
    RJGraham
    Jun 28, 2004
  2. Chris Goller
    Replies:
    4
    Views:
    386
    Jordan Stewart
    Mar 9, 2005
  3. Tony Eva
    Replies:
    1
    Views:
    497
    Jeff Epler
    Nov 9, 2003
  4. Vincent Texier
    Replies:
    3
    Views:
    2,414
    Vincent Texier
    Jul 1, 2004
  5. rh0dium
    Replies:
    6
    Views:
    278
    Dennis Lee Bieber
    Aug 5, 2005
Loading...

Share This Page