Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86187
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!ecngs!feeder2.ecngs.de!81.171.88.16.MISMATCH!hq-usenetpeers.eweka.nl!hq-usenetpeers.eweka.nl!bcyclone02.am1.xlned.com!bcyclone02.am1.xlned.com!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.000 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'resulting': 0.04; 'interpreter': 0.05; 'output': 0.05; '"""': 0.07; 'string': 0.09; 'escape': 0.09; 'mask': 0.09; 'output,': 0.09; 'subject:string': 0.09; 'unrecognized': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '(assuming': 0.16; '23,': 0.16; 'advantage.': 0.16; 'aiming': 0.16; 'ascii,': 0.16; 'backslash': 0.16; 'backslash,': 0.16; 'backslashes': 0.16; 'broken.': 0.16; 'broken.)': 0.16; 'debugging:': 0.16; 'finney': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'i.e.,': 0.16; 'letting': 0.16; 'likewise': 0.16; 'literals': 0.16; 'name),': 0.16; 'unchanged,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'obviously': 0.18; 'result.': 0.19; 'unlike': 0.19; 'feb': 0.22; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'error': 0.23; 'bytes': 0.24; 'comparing': 0.24; 'documented': 0.24; 'instance,': 0.24; 'refers': 0.24; 'stick': 0.24; 'mon,': 0.24; 'together.': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'recognized': 0.26; 'right.': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; '(this': 0.29; 'character': 0.29; "doesn't": 0.30; 'characters': 0.30; 'said,': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; 'towards': 0.31; 'changed.': 0.31; 'forces': 0.31; 'probably': 0.32; 'run': 0.32; 'quite': 0.32; 'text': 0.33; 'url:python': 0.33; 'reader': 0.33; 'actual': 0.34; "can't": 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'sequence': 0.36; 'useful': 0.36; 'url:org': 0.36; 'turn': 0.37; 'two': 0.37; 'easily': 0.37; 'being': 0.38; 'problems': 0.38; 'ben': 0.38; 'depends': 0.38; 'url:library': 0.38; 'pm,': 0.38; 'rather': 0.38; 'expect': 0.39; 'though,': 0.39; 'sure': 0.39; 'url:3': 0.61; "you're": 0.61; 'complete': 0.62; "you've": 0.63; 'more': 0.64; 'forward': 0.65; 'special': 0.74; 'behavior': 0.77; '2015': 0.84; 'distinguish': 0.84; "it'd": 0.84; 'start.': 0.84; 'url:reference': 0.84; 'to:none': 0.92; 'convinced': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=YBt/t2duT5loIxRq4/iLwEvSx/w22kW0YR0EOYy3quA=; b=oA5mpP0/LqL/rSPy8OZFmNuUQS4Du7nbV1YWJ9xAcOSzgWsFQ3UKggfy785x+WGK0o HzByPUkamxJUy5+YBIJZV2PIjNtb6v9ANmRZizlsmOnHDzBWSU2ddZXQQjeOiWTHEpY8 oIAAcDS0w9XzU/SA72XPq0RY9/Z8g06vf51kEelqNJ7hv53Oh+oDqCJMjUWWCf6XJpjV Tn0XHPLAE3vDqp/TjV0lZNcM53VHlx4Crox1qCOTo2aNBPrxNwKNJ2JCnnF7gdqAgfxf utJjbwe526+zh8RzpqVDXWUv1/ZFv4ybGiFIawgUBr3eySUkettgYFy0P/H+DQMQwzsT rsSg== |
| MIME-Version | 1.0 |
| X-Received | by 10.107.33.11 with SMTP id h11mr11048846ioh.53.1424661638664; Sun, 22 Feb 2015 19:20:38 -0800 (PST) |
| In-Reply-To | <85vbit73jd.fsf@benfinney.id.au> |
| References | <CAPTjJmqx3s1a0LL4RLgVB1PsOfyF9ryy6nwHwOwrQs1Zx2Hd-Q@mail.gmail.com> <85vbit73jd.fsf@benfinney.id.au> |
| Date | Mon, 23 Feb 2015 14:20:38 +1100 |
| Subject | Re: Unrecognized backslash escapes in string literals |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.19049.1424661646.18130.python-list@python.org> (permalink) |
| Lines | 49 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1424661646 news.xs4all.nl 2938 [2001:888:2000:d::a6]:55586 |
| X-Complaints-To | abuse@xs4all.nl |
| X-Received-Body-CRC | 2822446537 |
| X-Received-Bytes | 6733 |
| Xref | csiph.com comp.lang.python:86187 |
Show key headers only | View raw
On Mon, Feb 23, 2015 at 1:41 PM, Ben Finney <ben+python@benfinney.id.au> wrote:
> Right. Text strings literals are documented to work that way
> <URL:https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str>,
> which refers the reader to the language reference
> <URL:https://docs.python.org/3/reference/lexical_analysis.html#strings>.
BTW, quoting from that:
"""
Unlike Standard C, all unrecognized escape sequences are left in the
string unchanged, i.e., the backslash is left in the result. (This
behavior is useful when debugging: if an escape sequence is mistyped,
the resulting output is more easily recognized as broken.)
"""
I'm not sure it's more obviously broken. Comparing Python and Pike:
>>> "asdf\qwer"
'asdf\\qwer'
> "asdf\qwer";
(1) Result: "asdfqwer"
Which is the "more easily recognized as broken" depends on what the
actual intention was. If you wanted to have a backslash (eg a path
name), then the second one is, because you've just run two path
components together. If you wanted to have some sort of special
character ("\n"), then they're both going to be about the same - you'd
expect to see "\n" in the output, one has added a backslash (assuming
you're looking at the repr), the other has removed it. Likewise if you
wanted some other symbol (eg forward slash), they're about the same (a
doubled backslash, or a complete omission, same diff). But if you just
fat-fingered a backslash into a string where it completely doesn't
belong, then seeing a doubled backslash is definitely better than
seeing just the following character (which would mask the error
entirely). Since the interpreter can't know what the intention was, it
obviously has to do just one thing and stick with it.
I'm not convinced this is really an advantage. Python has been aiming
more and more towards showing problems immediately, rather than having
them depend on your data - for instance, instead of letting you treat
bytes and characters as identical until you hit something that isn't
ASCII, Py3 forces you to distinguish from the start. That said,
though, there's probably a lot of code out there that depends on
backslashes being non-special, so it's quite probably something that
can't be changed. But it'd be nice to be able to turn on a warning for
it.
ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Unrecognized backslash escapes in string literals Chris Angelico <rosuav@gmail.com> - 2015-02-23 14:20 +1100
csiph-web