for a function I’d like to test wether an argument is a number or a list.
the think is I don’t know the clean way to test wether a var is a list.
…and the isinstance(var, list) returns a :
TypeError: isinstance() arg 2 must be a class, type, or tuple of classes and types
strange, I just copy/paste it from a python doc.
here’s a quick summary test with a silly but working method at the end to recognize lists :
print '---'
a='string'
b=123
c=123.456
d=[1,2,3]
print type(a)
print type(a)==str
print type(b)
print type(b)==int
print type(c)
print type(c)==float
print type(d)
#print type(d)==list # returns False
#print isinstance(d,list) # bug
<b>print str(type(d))=="<type 'list'>"</b> # that's terrible I know. but it works
how do you do that ?
thanks !