Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #86184
| Path | csiph.com!usenet.pasdenom.info!news.franciliens.net!fdn.fr!usenet-fr.net!nerim.net!novso.com!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <davea@davea.name> |
| 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; 'python,': 0.02; 'resulting': 0.04; 'argument': 0.05; 'output': 0.05; '"""': 0.07; 'correct.': 0.07; 'ignored': 0.07; 'incompatible': 0.07; 'string': 0.09; 'escape': 0.09; 'inherited': 0.09; 'literal': 0.09; 'subject:string': 0.09; 'unrecognized': 0.09; 'python': 0.11; 'language,': 0.12; 'windows': 0.15; 'backslash': 0.16; 'broken.)': 0.16; 'character.': 0.16; 'debugging:': 0.16; 'definition.': 0.16; 'finney': 0.16; 'formatted': 0.16; 'i.e.,': 0.16; 'literals': 0.16; 'literals.': 0.16; 'slash': 0.16; 'unambiguous': 0.16; 'unchanged,': 0.16; 'language': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'result.': 0.19; 'programming': 0.22; 'shell': 0.22; 'header :User-Agent:1': 0.23; 'error': 0.23; 'documented': 0.24; 'refers': 0.24; 'sort': 0.25; 'define': 0.26; 'recognized': 0.26; 'right.': 0.26; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'chris': 0.29; '(this': 0.29; 'character': 0.29; "doesn't": 0.30; 'dos': 0.30; "i'm": 0.30; 'writes:': 0.31; 'languages': 0.32; 'text': 0.33; 'says': 0.33; 'url:python': 0.33; 'reader': 0.33; 'could': 0.34; 'problem': 0.35; 'definition': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'in:': 0.36; 'sequence': 0.36; 'done': 0.36; 'useful': 0.36; 'url:org': 0.36; 'should': 0.36; 'error.': 0.37; 'easily': 0.37; 'ben': 0.38; 'url:library': 0.38; 'needed': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'according': 0.40; 'even': 0.60; 'most': 0.60; 'url:3': 0.61; "you're": 0.61; 'such': 0.63; 'pick': 0.64; 'more': 0.64; 'different': 0.65; 'forward': 0.65; 'needing': 0.65; 'anything.': 0.68; 'received:74.208': 0.68; 'user,': 0.69; 'felt': 0.74; 'programs,': 0.74; 'behavior': 0.77; 'admission': 0.84; 'url:reference': 0.84; 'approach.': 0.91; 'have.': 0.93 |
| Date | Sun, 22 Feb 2015 22:01:52 -0500 |
| From | Dave Angel <davea@davea.name> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Unrecognized backslash escapes in string literals |
| References | <CAPTjJmqx3s1a0LL4RLgVB1PsOfyF9ryy6nwHwOwrQs1Zx2Hd-Q@mail.gmail.com> <85vbit73jd.fsf@benfinney.id.au> |
| In-Reply-To | <85vbit73jd.fsf@benfinney.id.au> |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Provags-ID | V02:K0:qcu/WTQAX7WlL+1BvP5+BebyoqaIfUONrswajA0C4s0 XJuSH3/YcjNZMGBnscJQl7jf/EgCqShno6ojRPz92AsSHlneef Wzxs2xKVB6HAOr+qMag6nSp+ea+uwVKiICb1SeKZD2pBqqhJ97 PIQ/1EKzckP4Xqla0xwR6fermL3Fw3z4Zd1YmczrVxhe67aCiL J/uFhPwz+/BU5CyGpqKmFSt9Bk7xuhfGvtceY1SfR+5TJ6Lua0 ruMnM4jFkKRymOb3EmhTECSGhwCR3INDnnZeq+YyZPqMsy6LZM 0StyAOj3B8BOb+G1UXdCjL/Fl8kPmrctApv8Vu+6rwrACRkjA= = |
| X-UI-Out-Filterresults | notjunk:1; |
| 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.19046.1424660528.18130.python-list@python.org> (permalink) |
| Lines | 65 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1424660528 news.xs4all.nl 2879 [2001:888:2000:d::a6]:47502 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:86184 |
Show key headers only | View raw
On 02/22/2015 09:41 PM, Ben Finney wrote: > Chris Angelico <rosuav@gmail.com> writes: > >> In Python, unrecognized escape sequences are treated literally, >> without (as far as I can tell) any sort of warning or anything. > > 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>. > >> Why is it that Python interprets them this way, and doesn't even give >> a warning? > > Because the interpretation of those literals is unambiguous and correct. Correct according to a misguided language definition. > > It's unfortunate that MS Windows inherited the incompatible “backslash > is a path separator”, long after backslash was already established in > many programming languages as the escape character. Windows "inherited" it from DOS. But since Windows was nothing but a DOS shell for several years, that's not surprising. The historical problem came from CP/M's use of the forward slash for a switch-character. Since MSDOS/PCDOS/QDOS was trying to permit transliterated CP/M programs, and because subdirectories were an afterthought (version 2.0), they felt they needed to pick a different character. At one time, the switch-character could be set by the user, but most programs ignored that, so it died. > >> Is there a way to enable such warnings/errors? > > A warning or error for a correctly formatted literal with an unambiguous > meaning would be an up-Pythonic thing to have. > > I can see the motivation, but really the best solution is to learn that > the backslash is an escape character in Python text string literals. > > This has the advantage that it's the same escape character used for text > string literals in virtually every other programming language, so you're > not needing to learn anything unusual. > I might be able to buy that argument if it was done the same way, but as it says in: https://docs.python.org/3/reference/lexical_analysis.html#strings """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.) """ The word "broken" is an admission that this was a flawed approach. If it's broken, it should be an error. I'm not suggesting that the implementation should falsely trigger an error. But that the language definition should be changed to define it as an error. -- DaveA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Unrecognized backslash escapes in string literals Dave Angel <davea@davea.name> - 2015-02-22 22:01 -0500
csiph-web