convert string to the "escaped string"

Discussion in 'Python' started by Petr Jakes, Nov 12, 2005.

  1. Petr Jakes

    Petr Jakes Guest

    Hi,
    I am trying to convert string to the "escaped string".
    example: from "0xf" I need "\0xf"
    I am able to do it like:

    a="0xf"
    escaped_a=("\%s" % a ).decode("string_escape")

    But it looks a little bit complicated in this beautiful language to me
    .....

    Regards

    Petr Jakes
    Petr Jakes, Nov 12, 2005
    #1
    1. Advertising

  2. Petr Jakes

    Petr Jakes Guest

    small mistake in my previous posting, sorry!!!!
    from "0xf" I need "\xf" of course
    and mentioned code gives me "\0xf" of course.

    Thanks for your postings

    Petr Jakes
    Petr Jakes, Nov 12, 2005
    #2
    1. Advertising

  3. Petr Jakes wrote:

    > I am trying to convert string to the "escaped string".
    > example: from "0xf" I need "\0xf"


    > I am able to do it like:
    >
    > a="0xf"
    > escaped_a=("\%s" % a ).decode("string_escape")
    >
    > But it looks a little bit complicated in this beautiful language to me


    I suspect that optimizing for people who want to turn "0xf" into
    chr(0) + "xf" isn't exactly a priority...

    if that's really what you want, of course. are you sure you didn't
    mean to write, say

    chr(int("0xf", 0))

    (that is, convert 0xf to a character) or

    repr(chr(int("0xf", 0)))

    (that is, convert 0xf to a character, and convert that character to a
    string literal)

    ?

    </F>
    Fredrik Lundh, Nov 12, 2005
    #3
  4. Petr Jakes

    Petr Jakes Guest

    Fredrik, thanks for your posting. I really appretiate your reply and
    your way how you kindly answer even stupid newbie's questions on this
    mailing list.
    I was trying: int("0xf") but I did not have idea about the optional
    "base" parameter for the int function.
    Thanks a lot.
    Petr
    Petr Jakes, Nov 12, 2005
    #4
    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. Andreas Klemt
    Replies:
    1
    Views:
    376
    Karl Seguin
    Jul 23, 2003
  2. Vance Kessler

    Re: Unescaping ASP vbscript escaped string

    Vance Kessler, Mar 1, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    2,573
    Vance Kessler
    Mar 1, 2004
  3. Enter The

    Splitting an escaped string

    Enter The, Oct 4, 2007, in forum: Java
    Replies:
    1
    Views:
    287
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=
    Oct 4, 2007
  4. Gregory Toomey

    how to convert a string to an escaped string

    Gregory Toomey, Feb 10, 2004, in forum: Perl Misc
    Replies:
    7
    Views:
    160
    Bart Lateur
    Feb 12, 2004
  5. Replies:
    2
    Views:
    170
    John Bokma
    Aug 30, 2013
Loading...

Share This Page