Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; '"> TypeError? Mime-Version: 1.0 (Apple Message framework v1283) Content-Type: multipart/alternative; boundary="Apple-Mail=_4DF62E96-9084-4335-9554-A462B8C15FCF" From: Roy Smith In-Reply-To: <20140609185728.3cac55ab@x34f> Date: Mon, 9 Jun 2014 12:53:59 -0400 References: <048960da-c132-407f-b1b3-4612a3dd7697@googlegroups.com> <20140609185728.3cac55ab@x34f> To: Paul Sokolovsky X-Mailer: Apple Mail (2.1283) Cc: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 96 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402332848 news.xs4all.nl 2838 [2001:888:2000:d::a6]:38704 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73050 --Apple-Mail=_4DF62E96-9084-4335-9554-A462B8C15FCF Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii On Jun 9, 2014, at 11:57 AM, Paul Sokolovsky wrote: > This is very Pythonic, Python is strictly typed language. There's no > way None could possibly be "inside" a string, so if you're trying to > look for it there, you're doing something wrong, and told so. Well, the code we've got is: hourly_data =3D [(t if status in 'CSRP' else None) for (t, = status) in hours] where status can be None. I don't think I'm doing anything wrong. I = wrote exactly what I mean :-) We've changed it to: hourly_data =3D [(t if (status and status in 'CSRP') else = None) for (t, status) in hours] but that's pretty ugly. In retrospect, I suspect: hourly_data =3D [(t if status in set('CSRP') else None) for = (t, status) in hours] is a little cleaner. --- Roy Smith roy@panix.com --Apple-Mail=_4DF62E96-9084-4335-9554-A462B8C15FCF Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
This is very = Pythonic, Python is strictly typed language. There's no
way None = could possibly be "inside" a string, so if you're trying to
look for = it there, you're doing something wrong, and told = so.

Well, the code we've got = is:

          =  hourly_data =3D [(t if status in 'CSRP' else None) for (t, status) = in hours]

where status can be None.  I = don't think I'm doing anything wrong.  I wrote exactly what I mean = :-)  We've changed it to:

  =         hourly_data =3D [(t if (status and status in = 'CSRP') else None) for (t, status) in = hours]

but that's pretty ugly.  In = retrospect, I suspect:

      =     hourly_data =3D [(t if status in set('CSRP') else None) = for (t, status) in hours]

is a little = cleaner.


---
Roy Smith

=
= --Apple-Mail=_4DF62E96-9084-4335-9554-A462B8C15FCF--