Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #73045

Re: None in string => TypeError?

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.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; 'example:': 0.03; 'else:': 0.03; '(at': 0.04; 'string': 0.09; 'false.': 0.09; 'raises': 0.09; 'subject:None': 0.09; 'subject:string': 0.09; 'python': 0.11; 'assume': 0.14; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'iterable:': 0.16; 'iterated': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'roy': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; 'seems': 0.21; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'string,': 0.24; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'that.': 0.31; '>>>>': 0.31; 'entirely': 0.33; 'noticed': 0.34; 'equal': 0.35; 'false': 0.36; 'subject:?': 0.36; 'same.': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'smith': 0.68; "'foo'": 0.84
X-CM-Score 0.00
X-CNFS-Analysis v=2.1 cv=OZcWD3jY c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=1oDRhzKAKukA:10 a=UN7m2zo_qFIA:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=hIsiRbdy22Ab4-ghcUcA:9 a=QEXdDO2ut3YA:10
X-AUTH mrabarnett:2500
Date Mon, 09 Jun 2014 17:06:01 +0100
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0
MIME-Version 1.0
To python-list@python.org
Subject Re: None in string => TypeError?
References <048960da-c132-407f-b1b3-4612a3dd7697@googlegroups.com>
In-Reply-To <048960da-c132-407f-b1b3-4612a3dd7697@googlegroups.com>
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
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.10923.1402330151.18130.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1402330151 news.xs4all.nl 2956 [2001:888:2000:d::a6]:46038
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:73045

Show key headers only | View raw


On 2014-06-09 16:34, Roy Smith wrote:
> 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.
>
When working with strings, it's not entirely the same. For example:

 >>> 'oo' in 'foo'
True

If you iterated over the string, it would return False.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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