[Zope] python script and dealing with NULL parameter

Tino Wildenhain tino at wildenhain.de
Fri Oct 15 14:44:29 EDT 2004


Hi,

Am Fr, den 15.10.2004 schrieb Laura McCord um 20:24:
> I noticed that when the parameter is Null I get a Type Error
> Unsubscriptable object. Is there a python function or an if statement
> that will fix this?

There is no "null" in Python. The equivalence to that
(and I suspect you are talking about this) is None.
Usually database adaptors map SQL "null" to Python None.

In python you have: 
is None
==None
to check.
In most situations, boolean algebra is more convient:

None, "", '', {}, (), [] and so on are logically "false".

if maybe_none:  will only used if true or not one of the above
values

also:

maybe_none or "defaultvalue"  is usefull if you like
functional programming (list comprehensions for example)


(value is None and "No pricetag") or ("$ %0.2f" % value)

would be an expression for full functional programming using
boolean algebra :-)
(try it out with different values from python command line)


Regards
Tino






More information about the Zope mailing list