ConditionalPython

This is really rather simple, but I always have to figure it out every time I want to use it. It works somewhat like the C construct conditional ? value1 : value2. There are some conditions where it fails, so be careful where you use it. I will add some of these examples when I work them out.

In [11]: v = 'NULL'

In [12]: isinstance(v, int) and v or 0
Out[12]: 0

In [13]: v = 22

In [14]: isinstance(v, int) and v or 0
Out[14]: 22

ConditionalPython (last edited 2009-03-14 02:16:41 by CarlNobile)