is parameter an iterable?

Duncan Booth duncan.booth at invalid.invalid
Thu Nov 17 09:55:33 CET 2005

Steven D'Aprano wrote:

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

if 'iter' not in dir(__builtins__):
	import sys
	sys.exit('Archaic Python not supported, please upgrade')

Alternatively fill in the blanks with appropriate fallback code:

if 'iter' not in dir(__builtins__):
	def iter(obj):
    	   ... remainder of definition left as an exercise ...
     __builtins__.iter = iter

where iter does roughly what the iter builtin does.

More information about the Python-list mailing list