Why would I get a TypeEror?

Harper, Gina gharper at medplus.com
Wed Jan 12 13:19:35 EST 2005


Because you can't take the len() of an integer.  Try casting a as a str:
b=(1,len(str(a)))[isinstance(a,(list,tuple,dict))]

-----Original Message-----
From: It's me [mailto:itsme at yahoo.com] 
Sent: Wednesday, January 12, 2005 12:35 PM
To: python-list at python.org
Subject: Why would I get a TypeEror?


For this code snip:

a=3
....
b=(1,len(a))[isinstance(a,(list,tuple,dict))]

Why would I get a TypeError from the len function?

Thanks,






More information about the Python-list mailing list