None in string => TypeError?

Roy Smith roy at panix.com
Mon Jun 9 12:53:59 EDT 2014


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 = [(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 = [(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 = [(t if status in set('CSRP') else None) for (t, status) in hours]

is a little cleaner.


---
Roy Smith
roy at panix.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140609/8664ff0c/attachment.html>


More information about the Python-list mailing list