# encoding: utf-8 try: from itertools import imap except ImportError: print("Using map instead of itertools.imap (Python 3)") imap = map import sys def f(o): """A simple no-op function for testing imap()""" return o class MyIterable(object): """A minimal class which is iterable""" def __init__(self): # A simple set of data to pass to imap() self.data = [1,2,3] def __iter__(self): return imap(f, self.data) def main(argv): # In Jython 2.5 and CPython 2.7 and 3.2 this prints 1 2 3; # In Jython 2.7 it prints nothing print("Running ...") for obj in MyIterable(): print(obj) # In both Jython 2.5 and 2.7 this prints 1 2 3 #for obj in iter(MyIterable()): # print(obj) print("\nDone.") # end main() if __name__ == '__main__': main(sys.argv[1:])