On 12.01.2005, at 18:35, It's me wrote:

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?

the problem is, that (1,len(a)) is evaluated, neither what type a actually has
(python has no builtin lazy evaluation like ML). You have to do it this way
instead:


a=3
...
b = isinstance(a,(list,tuple,dict)) and len(a) or 1

- harold -

--
The opposite of a correct statement is a false statement.
But the opposite of a profound truth may be another profound truth.
-- Niels Bohr

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to