is variable a list?
Evgeny Roubinchtein
eroubinc at u.washington.edu
Sat Jan 8 02:02:05 EST 2000
>>>>> "James" == James Punteney <jamesp at simplypets.com> writes:
James> Is there some way to determine whether a variable is list
James> or a string? Basically I have a variable that I would like
James> to be able to be a string or a list, but I need some way to
James> tell which it is.
Besides using the type() function you could also use the types module
and the isinstance() function:
>>> l=[]
>>> s=''
>>> import types
>>> isinstance(l, types.ListType)
1
>>> isinstance(l, types.StringType)
0
>>> isinstance(s, types.StringType)
1
>>> isinstance(s, types.ListType)
0
Hmm, I guess TIMTOWDY _sometimes_ applies to Python :-).
--
Evgeny.
More information about the Python-list
mailing list