[Zope] python script and dealing with NULL parameter
Laura McCord
Laura.McCord at doucet-austin.com
Fri Oct 15 15:26:21 EDT 2004
Thanks Tino,
if notes is None:
notes = 'none'
else:
notes=notes[0:35]
return notes
Using None worked. There are still some keywords and functions in python
that I am still learning.
Thanks Again,
Laura
-----Original Message-----
From: Tino Wildenhain [mailto:tino at wildenhain.de]
Sent: Friday, October 15, 2004 1:44 PM
To: Laura McCord
Cc: zope at zope.org
Subject: Re: [Zope] python script and dealing with NULL parameter
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