[newbie questions] if conditions - if isset - if empty

Chris Angelico rosuav at gmail.com
Sat Apr 14 18:45:55 EDT 2012


On Sun, Apr 15, 2012 at 8:41 AM, Mahmoud Abdel-Fattah
<accounts at abdel-fattah.net> wrote:
> item['author_brand'] = author_brand.group(2) if type(author_brand) != None
> else ''

Almost there! :)

None is a singleton, not a type; you don't need to check
type(author_brand) but rather its identity. Use "author_brand is not
None" for your condition and it should work like you're expecting. In
this case, you can actually just use "author_brand" as your condition
(no quotes, of course), as None evaluates as false.

Chris Angelico



More information about the Python-list mailing list