is parameter an iterable?

Steven D'Aprano steve at REMOVEMEcyber.com.au
Thu Nov 17 02:53:14 EST 2005


Ah, found the right solution! Thanks to Fredrik Lundh 
for so gently pointing me at this post. Just one 
question, if I may:-

Alex Martelli wrote:

> It's not hard...:
> 
> try:
>     _it = iter(whatever)
> except TypeError:
>     print 'non-iterable'
> else:
>     for i in _it: # etc, etc


Alas and alack, I have to write code which is backwards 
compatible with older versions of Python:

Python 2.1.1 (#1, Aug 25 2001, 04:19:08)
[GCC 3.0.1] on sunos5
Type "copyright", "credits" or "license" for more 
information.
 >>> iter
Traceback (most recent call last):
   File "<stdin>", line 1, in ?
NameError: name 'iter' is not defined

What should I do when I can't rely on functions that 
don't exist in older versions of Python?


-- 
Steven.




More information about the Python-list mailing list