How to detect what type a variable is?
grante at visi.com
Wed Nov 29 18:00:51 CET 2006
On 2006-11-29, eduardo.padoan at gmail.com <eduardo.padoan at gmail.com> wrote:
> Leandro Ardissone wrote:
>> I want to know what type is a variable.
>> For example, I get the contents of an xml but some content is a list or
>> a string, and I need to know what type it is.
> You should try to treat it as a list, catch the exceptions raise when
> it is a string (problably ValueError, TypeError ou Attribute error,
> depends on what are you doing),
As you said, it depends on what he's doing. The problem is
that strings act a lot like lists, and if he's using the subset
of list characteristics that are implimented by strings, there
won't _be_ an exception -- just wrong results.
In the past, I've almost alwasy had to look before I leap when
dealing with both strings and lists.
Grant Edwards grante Yow! How's it going in
at those MODULAR LOVE UNITS??
More information about the Python-list