Length of an Unsized Object

Stephen Hansen apt.shansen at gmail.com
Thu Dec 31 12:01:09 EST 2009


On Thu, Dec 31, 2009 at 8:09 AM, Victor Subervi <victorsubervi at gmail.com>wrote:

> Hi;
> I have this code:
>
>         sql = 'describe %s %s;' % (optionsStore, option)
>         print sql
>         cursor.execute(sql)
>         descr = cursor.fetchone()
>         if len(descr) is not None:
>
> Python complains:
>
> *TypeError*: len() of unsized object
>
> Please advise how to rewrite the last line so as to avoid the infamous
> try/except.
>

The test itself makes no sense; len returns an integer, and can never be
None.

Simply do:

   if descr:

HTH,

--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091231/8855b2e9/attachment-0001.html>


More information about the Python-list mailing list