String handling bug in Python

Anders J. Munch andersjm at dancontrol.dk
Wed Apr 24 05:02:53 EDT 2002


<jepler at unpythonic.net> wrote:
> On Wed, Apr 24, 2002 at 12:57:02PM +1200, Colin Brown wrote:
> > Thanks guys
> >
> > I did not think to look up this  "documented feature", sorry.

Not your fault, Colin, after all it's in the reference manual which the docs
refers to as "for language lawyers".  A lot of (most?) newbies trip over
this.  (Well I did anyway ;-)

>
> Well, how else would you suggest that "raw" strings should work?  For
> instance, if you want to let
>     r'\' == '\\'
> how will you write the raw string that equals "\\'"?

Python raw strings are delineated like this:
  A raw string ends at the first matching quote character which is not
  preceded by an odd number of consecutive backslashes.

It would be great if I could have written this instead:
  A raw string ends at the first matching quote character.

Much simpler, every bit as useful and - dare I say it - more pythonic
than the current semantics.

The paragraph Andrew quoted from the reference manual could then be
shortened to:

"When an `r' or `R' prefix is present, the backslash character is not
subject to any kind of special interpretation."

A raw string that equals "\\'"?  I would write that r"\'".

I-just-hope-MSOE-will-let-me-post-this-unmangled-ly-y'rs, Anders






More information about the Python-list mailing list