Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #73046
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <i@introo.me> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'else:': 0.03; '(at': 0.04; 'string': 0.09; 'raises': 0.09; 'received:209.85.219': 0.09; 'subject:None': 0.09; 'subject:string': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'assume': 0.14; 'containers': 0.16; 'iterable:': 0.16; 'roy': 0.16; 'tuple,': 0.16; 'typeerror:': 0.16; 'which,': 0.16; 'bit': 0.19; 'seems': 0.21; '>>>': 0.22; 'cc:addr:python.org': 0.22; '>>>': 0.24; 'documented': 0.24; 'cc:2**0': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'needed.': 0.30; 'restrict': 0.30; 'message-id:@mail.gmail.com': 0.30; 'that.': 0.31; 'comparison': 0.31; 'url:python': 0.33; 'totally': 0.33; 'noticed': 0.34; 'sense': 0.34; 'received:209.85': 0.35; 'equal': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'received:209': 0.37; 'skip:& 10': 0.38; 'list,': 0.38; 'that,': 0.38; 'little': 0.38; 'according': 0.40; 'url:3': 0.61; 'here:': 0.62; 'charset:iso-2022-jp': 0.65; 'smith': 0.68; 'default': 0.69; 'url:me': 0.69; "'foo'": 0.84; 'skip:\x1b 30': 0.84; 'url:reference': 0.84; 'str.': 0.91; 'hand,': 0.93 |
| X-Google-DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=h5rDRNa086XRtj41N5aeyhux4Pp58lKTMP1cyc+QT+E=; b=m69JD1yb+8vtx6BMNNQxnouBICRBVnY2vj2xJZ9udRoIFGJ6OytFJY0wLotKAz5gRo eKuBgbGDwuMoj8tD3/zx9XUMOkhfR30OibJl54n2BOXDc8jx57AH4dMZ5oyPTgp2bFel z6ED++zMCILHSzj2q2WxUFsI6zPiA5+9242dNZVGWHHg051aMeEcwUAYfRo7Em7rdxNR Qj8mPiEMZPt0FbrqzbITqgOm7G6TZZY2KvJ9prlRX+oiBP9DV27kZDYvDgnrcAJWgHGz uRGsZfS8OBpJ1u8XBVDKWAk1SV3WrbVx56mtVya5bF7YEJePHRbm3KJBMBCRnrpL32AR m6DQ== |
| X-Gm-Message-State | ALoCoQlWhzWxp3BeqiHEk83iK5jRaND5Mi4a9/GPhy6MAPRG/+vNzNLVisQK6PTXsFSEVS98W2XM |
| MIME-Version | 1.0 |
| X-Received | by 10.60.94.75 with SMTP id da11mr26908887oeb.43.1402330429084; Mon, 09 Jun 2014 09:13:49 -0700 (PDT) |
| X-Originating-IP | [143.89.76.162] |
| In-Reply-To | <048960da-c132-407f-b1b3-4612a3dd7697@googlegroups.com> |
| References | <048960da-c132-407f-b1b3-4612a3dd7697@googlegroups.com> |
| Date | Tue, 10 Jun 2014 00:13:49 +0800 |
| Subject | Re: None in string => TypeError? |
| From | Shiyao Ma <i@introo.me> |
| To | Roy Smith <roy@panix.com> |
| Content-Type | multipart/alternative; boundary=089e011603f4169c9d04fb697f86 |
| Cc | Python <python-list@python.org> |
| 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.10924.1402330438.18130.python-list@python.org> (permalink) |
| Lines | 82 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1402330438 news.xs4all.nl 2960 [2001:888:2000:d::a6]:51262 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:73046 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
2014-06-09 23:34 GMT+08:00 Roy Smith <roy@panix.com>: > We noticed recently that: > > >>> None in 'foo' > > raises (at least in Python 2.7) > > TypeError: 'in <string>' requires string as left operand, not NoneType > > This is surprising. The description of the 'in' operatator is, 'True if > an item of s is equal to x, else False '. From that, I would assume it > behaves as if it were written: > > for item in iterable: > if item == x: > return True > else: > return False > > why the extra type check for str.__contains__()? That seems very > unpythonic. Duck typing, and all that. > It's a little bit inconsistent. But it's clearly documented here: https://docs.python.org/3/reference/expressions.html#in Which, according to its own logic, the string is not a *container* type. It's just some chars, and that totally makes sense for to restrict the type of x in "str" to be convertible to type str. On the other hand, containers like list, and tuple, they are heterogeneous by default in Python, so a item by item comparison is needed. -- 吾輩は猫である。ホームーページはhttp://introo.me。
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
None in string => TypeError? Roy Smith <roy@panix.com> - 2014-06-09 08:34 -0700
Re: None in string => TypeError? Ryan Hiebert <ryan@ryanhiebert.com> - 2014-06-09 10:42 -0500
Re: None in string => TypeError? Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-09 09:50 -0600
Re: None in string => TypeError? Paul Sokolovsky <pmiscml@gmail.com> - 2014-06-09 18:57 +0300
Re: None in string => TypeError? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-06-09 16:14 +0000
Re: None in string => TypeError? Chris Angelico <rosuav@gmail.com> - 2014-06-10 02:31 +1000
Re: None in string => TypeError? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-06-09 16:07 +0000
Re: None in string => TypeError? MRAB <python@mrabarnett.plus.com> - 2014-06-09 17:06 +0100
Re: None in string => TypeError? Shiyao Ma <i@introo.me> - 2014-06-10 00:13 +0800
Re: None in string => TypeError? Roy Smith <roy@panix.com> - 2014-06-09 12:53 -0400
Re: None in string => TypeError? Chris Angelico <rosuav@gmail.com> - 2014-06-10 02:59 +1000
Re: None in string => TypeError? Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-09 11:22 -0600
Re: None in string => TypeError? Chris Angelico <rosuav@gmail.com> - 2014-06-10 03:40 +1000
Re: None in string => TypeError? Ian Kelly <ian.g.kelly@gmail.com> - 2014-06-09 11:58 -0600
Re: None in string => TypeError? Chris Angelico <rosuav@gmail.com> - 2014-06-10 04:02 +1000
csiph-web