Re: Why would I get a TypeEror?

2005-01-16 Thread Stian Soiland
På 14. jan 2005 kl. 22:58 skrev Steven Bethard: (Any mac users? How do I fix this to appear in Norwegian? =) Note that if you're not comfortable with short-circuiting behavior, you can also code this using lazy evaluation: (lambda: 1/x, lambda: 1.0e99)[x==0]() .. and people wonder why so

Re: Why would I get a TypeEror?

2005-01-14 Thread It's me
Say again??? Reinhold Birkenfeld [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] It's me wrote: Sorry if my question was a little lazy and yes, I was asking about the lazy evaluation. :=) I am surprised about this (and this can be dangerous, I guess). If this is true, I

Re: Why would I get a TypeEror?

2005-01-14 Thread Reinhold Birkenfeld
Steven Bethard wrote: It's me wrote: Say again??? Please stop top-posting -- it makes it hard to reply in context. Reinhold Birkenfeld wrote... It's me wrote: If this is true, I would run into trouble real quick if I do a: (1/x,1.0e99)[x==0] Lazy evaluation: use the (x==0 and 1e99 or

RE: Why would I get a TypeEror?

2005-01-13 Thread Harper, Gina
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:[EMAIL PROTECTED] Sent: Wednesday, January 12, 2005 12:35 PM To: python-list@python.org Subject: Why would I get a TypeEror

Why would I get a TypeEror?

2005-01-12 Thread It's me
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, -- http://mail.python.org/mailman/listinfo/python-list

Re: Why would I get a TypeEror?

2005-01-12 Thread harold fellermann
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? because len() works only for sequence and mapping objects: help(len) Help on built-in function len in module __builtin__: len(...)

Re: Why would I get a TypeEror?

2005-01-12 Thread harold fellermann
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

Re: Why would I get a TypeEror?

2005-01-12 Thread Peter Hansen
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? What did you expect the length of the integer 3 to be? -Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: Why would I get a TypeEror?

2005-01-12 Thread It's me
Sorry if my question was a little lazy and yes, I was asking about the lazy evaluation. :=) I am surprised about this (and this can be dangerous, I guess). If this is true, I would run into trouble real quick if I do a: (1/x,1.0e99)[x==0] and that's not good. Something to keep in mind. :-(

Re: Why would I get a TypeEror?

2005-01-12 Thread Steve Holden
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? Thanks, because the interpreter evaluates the tuple (1, len(a)) before applying the indexing to it. You are trying to be far too clever. The standard way

Re: Why would I get a TypeEror?

2005-01-12 Thread Steven Bethard
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? You're looking for lazy evaluation or short-circuiting behavior. Python provides one form of short circuiting behavior with 'and' and 'or', though you