ANN: generator_tools-0.1 released

Kay Schluehr kay.schluehr at gmx.net
Tue Oct 9 03:21:20 EDT 2007


Originally I came up with the idea of a pure Python implementation for
copyable generators as an ActiveState Python Cookbook recipe. Too bad,
it was badly broken as Klaus Müller from the SimPy project pointed
out. Two weeks and lots of tests later I got finally a running version
that works not only in the very most simple use cases. As the code
size increased it turned out to not really fit anymore into the
"recipe" category and I created a package called "generator_tools".

generator_tools-0.1 is available for both Python 2.5 and Python 3.0
(!)

The generator_tools package can be downloaded from PyPI

    http://pypi.python.org/pypi/generator_tools/0.1

More information is presented on my project homepage

    http://www.fiber-space.de

Documentation is also included in the distribution.

Usage:
----------

from generator_tools.copygenerators import*
from generator_tools.picklegenerators import*

def f(start):
	i = start
	while i<start+10:
		yield i
		i+=1

>>> f_gen = f(5)
>>> f_gen.next()   # or next(f_gen) in Python 3.0
5
>>> f_gen.next()
6
>>> g_gen = copy_generator(f_gen)
>>> h_gen = copy_generator(f_gen)
>>> g_gen.next()
7
>>> h_gen.next()
7
>>> pickler = GeneratorPickler("test.pkl")
>>> pickler.pickle_generator(g_gen)
>>> k_gen = pickler.unpickle_generator()
>>> list(g_gen) == list(k_gen)
True




More information about the Python-list mailing list