Raw strings to normal strings conversion?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Nagarajan

    Raw strings to normal strings conversion?

    Is there a way by which I could obtain normal string form of a raw
    string.
    XML CDATA is returned as raw string. But I need the string to actually
    escape special chars.

    Any idea?

  • James Stroud

    #2
    Re: Raw strings to normal strings conversion?

    Nagarajan wrote:
    Is there a way by which I could obtain normal string form of a raw
    string.
    XML CDATA is returned as raw string. But I need the string to actually
    escape special chars.
    >
    Any idea?
    >
    This doesn't seem clear. Perhaps an example of what you get and what you
    want it converted to.

    In the meantime, see if urllib.unquote( ) doesn't do what you need.

    James

    Comment

    • Nagarajan

      #3
      Re: Raw strings to normal strings conversion?

      On Aug 23, 1:21 pm, James Stroud <jstr...@mbi.uc la.eduwrote:
      Nagarajan wrote:
      Is there a way by which I could obtain normal string form of a raw
      string.
      XML CDATA is returned as raw string. But I need the string to actually
      escape special chars.
      >
      Any idea?
      >
      This doesn't seem clear. Perhaps an example of what you get and what you
      want it converted to.
      Here is an example:
      >rawstr = r'a\nb'
      >print rawstr
      a\nb

      Now I need this newstr to actually interpret '\n', in other words, to
      behave like a normal string.
      >
      In the meantime, see if urllib.unquote( ) doesn't do what you need.
      >
      James
      And yes, unquote doesn't help.

      Comment

      • Marc 'BlackJack' Rintsch

        #4
        Re: Raw strings to normal strings conversion?

        On Thu, 23 Aug 2007 09:21:40 +0000, Nagarajan wrote:
        On Aug 23, 1:21 pm, James Stroud <jstr...@mbi.uc la.eduwrote:
        >Nagarajan wrote:
        Is there a way by which I could obtain normal string form of a raw
        string.
        XML CDATA is returned as raw string. But I need the string to actually
        escape special chars.
        >>
        Any idea?
        >>
        >This doesn't seem clear. Perhaps an example of what you get and what you
        >want it converted to.
        >
        Here is an example:
        >>rawstr = r'a\nb'
        >>print rawstr
        a\nb
        >
        Now I need this newstr to actually interpret '\n', in other words, to
        behave like a normal string.
        So you get a string with Newlines as two character sequence \n. You don't
        get "raw" strings. That is a concept in Python source code. When the
        program is running there is no such distinction between "raw" and "normal"
        strings. Here's a solution:

        In [87]: print r'a\nb'
        a\nb

        In [88]: print r'a\nb'.decode( 'string-escape')
        a
        b

        Ciao,
        Marc 'BlackJack' Rintsch

        Comment

        • Nagarajan

          #5
          Re: Raw strings to normal strings conversion?

          On Aug 23, 2:42 pm, Marc 'BlackJack' Rintsch <bj_...@gmx.net wrote:
          On Thu, 23 Aug 2007 09:21:40 +0000, Nagarajan wrote:
          On Aug 23, 1:21 pm, James Stroud <jstr...@mbi.uc la.eduwrote:
          Nagarajan wrote:
          Is there a way by which I could obtain normal string form of a raw
          string.
          XML CDATA is returned as raw string. But I need the string to actually
          escape special chars.
          >
          Any idea?
          >
          This doesn't seem clear. Perhaps an example of what you get and what you
          want it converted to.
          >
          Here is an example:
          >rawstr = r'a\nb'
          >print rawstr
          a\nb
          >
          Now I need this newstr to actually interpret '\n', in other words, to
          behave like a normal string.
          >
          So you get a string with Newlines as two character sequence \n. You don't
          get "raw" strings. That is a concept in Python source code. When the
          program is running there is no such distinction between "raw" and "normal"
          strings. Here's a solution:
          >
          In [87]: print r'a\nb'
          a\nb
          >
          In [88]: print r'a\nb'.decode( 'string-escape')
          a
          b
          >
          Ciao,
          Marc 'BlackJack' Rintsch
          Thanks a lot.

          Comment

          Working...