Q: quoting string without escapes

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

    #1

    Q: quoting string without escapes

    in Python, is there a way to quote a string as to avoid escaping ' or "
    inside the string?

    i.e. like Perl's q or qq.
    thanks.

    Xah
    xah@xahlee.org


  • Steve Holden

    #2
    Re: Q: quoting string without escapes

    Xah Lee wrote:
    [color=blue]
    > in Python, is there a way to quote a string as to avoid escaping ' or "
    > inside the string?
    >
    > i.e. like Perl's q or qq.
    > thanks.
    >
    > Xah
    > xah@xahlee.org
    > http://xahlee.org/PageTwo_dir/more.html
    >[/color]
    Aren't you the guy who's telling the whole world how to write Python and
    Perl? Unusual to find arrogance and humility in such close proximity.

    Please stop cross-posting your ill-informed and inflammatory stuff to
    c.l.py and c.l.perl.m. And now I have your attention, the answer to your
    question is ...

    Use triple-quoting.

    followups-set'ly y'rs - steve
    --
    Steve Holden http://www.holdenweb.com/
    Python Web Programming http://pydish.holdenweb.com/
    Holden Web LLC +1 703 861 4237 +1 800 494 3119

    Comment

    • Daniel Bickett

      #3
      Re: Q: quoting string without escapes

      On Mon, 31 Jan 2005 14:09:10 -0500, Steve Holden <steve@holdenwe b.com> wrote:[color=blue]
      > Use triple-quoting.[/color]

      An example, for the sake of examples:

      Python 2.3.4 (#53, May 25 2004, 21:17:02) [MSC v.1200 32 bit (Intel)] on win32
      Type "help", "copyright" , "credits" or "license" for more information.[color=blue][color=green][color=darkred]
      >>> string = """ " ' " ' " ' " ' \""" """
      >>> string[/color][/color][/color]
      ' " \' " \' " \' " \' """ '[color=blue][color=green][color=darkred]
      >>> string = """[/color][/color][/color]
      .... "
      .... "
      .... "
      .... '
      .... '
      .... '
      .... \"""
      .... "\""
      .... ""\"
      .... """[color=blue][color=green][color=darkred]
      >>> string[/color][/color][/color]
      '\n"\n"\n"\n\'\ n\'\n\'\n"""\n" ""\n"""\n'

      --
      Daniel Bickett
      dbickett at gmail.com

      Comment

      Working...