Raw String Question

Jim Garrison jgarrison at troux.com
Thu Mar 12 13:59:45 EDT 2009


I'm an experienced Perl developer learning Python, but I seem to
be missing something about raw strings.  Here's a transcript of
a Python shell session:

  Python 3.0 (r30:67507, Dec  3 2008, 20:14:27) [MSC v.1500 32 bit 
(Intel)] on win32
  Type "copyright", "credits" or "license()" for more information.

      ****************************************************************
      Personal firewall software may warn about the connection IDLE
      makes to its subprocess using this computer's internal loopback
      interface.  This connection is not visible on any external
      interface and no data is sent to or received from the Internet.
      ****************************************************************

  IDLE 3.0
  >>> r"a\b"
  'a\\b'
  >>> r"a\"
  SyntaxError: EOL while scanning string literal (<pyshell#45>, line 1)
  >>> r"a\ "
  'a\\ '
  >>> r"a\""
  'a\\"'

It seems the parser is interpreting the backslash as an escape
character in a raw string if the backslash is the last character.
Is this expected?



More information about the Python-list mailing list