[newbie questions] if conditions - if isset
MRAB
python at mrabarnett.plus.com
Sat Apr 14 19:00:16 EDT 2012
More information about the Python-list mailing list
Sat Apr 14 19:00:16 EDT 2012
- Previous message (by thread): [newbie questions] if conditions - if isset - if empty
- Next message (by thread): [newbie questions] if conditions - if isset - if empty
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 14/04/2012 23:45, Chris Angelico wrote: > 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. > re.match(...) returns either a match object or None. In a condition, a match object always evaluates as True and None always evaluates as False.
- Previous message (by thread): [newbie questions] if conditions - if isset - if empty
- Next message (by thread): [newbie questions] if conditions - if isset - if empty
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list