Re: how can i check whether a variable is iterable in my code?

2008-09-21 Thread James Mills
satoru, I should point out that the normal approach is to just try whatever it is that you're doing, and let it fail where it fails. For example: def processSeq(x): for i in x: print i processSeq([1, 2, 3]) processSeq("foobar") processSeq(5) <-- This will fail. cheers James On Sat, Se

Re: how can i check whether a variable is iterable in my code?

2008-09-20 Thread Terry Reedy
satoru wrote: On Sep 20, 6:35 pm, Aidan <[EMAIL PROTECTED]> wrote: satoru wrote: hi, all i want to check if a variable is iterable like a list, how can i implement this? this would be one way, though I'm sure others exist: if hasattr(yourVar, '__iter__'): # do stuff thank you,but th

Re: how can i check whether a variable is iterable in my code?

2008-09-20 Thread satoru
thanks very much! -- http://mail.python.org/mailman/listinfo/python-list

Re: how can i check whether a variable is iterable in my code?

2008-09-20 Thread John Machin
On Sep 20, 8:54 pm, satoru <[EMAIL PROTECTED]> wrote: > On Sep 20, 6:35 pm, Aidan <[EMAIL PROTECTED]> wrote: > > > satoru wrote: > > > hi, all > > > i want to check if a variable is iterable like a list, how can i > > > implement this? > > > this would be one way, though I'm sure others exist: > >

Re: how can i check whether a variable is iterable in my code?

2008-09-20 Thread Vito De Tullio
satoru wrote: > hi, all > i want to check if a variable is iterable like a list, how can i > implement this? untested def is_iterable(param): try: iter(param) except TypeError: return False else: return True -- By ZeD -- http://mail.python.org/mailman/listinfo/python-list

Re: how can i check whether a variable is iterable in my code?

2008-09-20 Thread satoru
On Sep 20, 6:35 pm, Aidan <[EMAIL PROTECTED]> wrote: > satoru wrote: > > hi, all > > i want to check if a variable is iterable like a list, how can i > > implement this? > > this would be one way, though I'm sure others exist: > > if hasattr(yourVar, '__iter__'): >         # do stuff thank you,but

Re: how can i check whether a variable is iterable in my code?

2008-09-20 Thread Aidan
satoru wrote: hi, all i want to check if a variable is iterable like a list, how can i implement this? this would be one way, though I'm sure others exist: if hasattr(yourVar, '__iter__'): # do stuff -- http://mail.python.org/mailman/listinfo/python-list

how can i check whether a variable is iterable in my code?

2008-09-20 Thread satoru
hi, all i want to check if a variable is iterable like a list, how can i implement this? -- http://mail.python.org/mailman/listinfo/python-list