TypeNone field detection
Mensanator
mensanator at aol.com
Wed Apr 16 21:16:33 EDT 2008
On Apr 16, 7:24 pm, Joe Blow <joeb... at nowhere.nohow> wrote:
> What is the best way to detect a TypeNone field in a tuple, or in a list?
>
> I am accessing a MySQL database using the MySQLdb Python interface... this
> interface returns a tuple object type in response to SQL SELECT
> statements. My understanding of the MySQLdb interface is that NULL
> database values are returned as a Python 'None' object.
>
> Because I need to create some work fields based on the contents of the
> database I am doing so by copying the tuple to a list object and then
> calculating these work fields as needed. My problem is that I need to be
> able to detect the Python 'None' objects and convert them to an integer
> zero value field to enable my calculations to work.
>
> I'm new to Python so I'm sure I'm overlooking something simple – but what
> is the easiest way to do a logical test for the existence of a TypeNone
> field?
>>> a = 0
>>> a==None
False
>>> b = None
>>> b==None
True
>>> type(a)
<type 'int'>
>>> type(b)
<type 'NoneType'>
More information about the Python-list
mailing list