Length of an Unsized Object

MRAB python at mrabarnett.plus.com
Thu Dec 31 12:09:05 EST 2009


Victor Subervi 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.

What is the value of descr when it raises that exception? Try printing
descr (or repr(descr)) to find out.

BTW, len() always returns an int, so "len(descr) is not None" is always
true.



More information about the Python-list mailing list