[Tutor] Python file escaping issue?
Steven D'Aprano
steve at pearwood.info
Mon Feb 22 13:52:12 CET 2010
On Mon, 22 Feb 2010 06:37:21 pm spir wrote:
> > It *seems* to work, because \d is left as backlash-d. But then you
> > do this, and wonder why you can't open the file:
>
> I consider this misleading, since it can only confuse newcomers.
> Maybe "lonely" single backslashes (not forming a "code" with
> following character(s)) should be invalid. Meaning literal
> backslashes would always be doubled (in plain, non-raw, strings).
> What do you think?
Certainly it can lead to confusion for beginners, but it follows the
convention of languages like bash and (I think) C++.
There are three main ways to deal with an unrecognised escape sequence:
* raise an error
* ignore the backslash, e.g. \d -> d
* keep the backslash, e.g. \d -> \d
There are good arguments for all three, so I don't think you'll get
consensus for any change.
--
Steven D'Aprano
More information about the Tutor
mailing list