ANN: generator_tools-0.1 released

K

Kay Schluehr

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
True
 
S

Steven Bethard

Kay said:
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
(!) [snip]True

This seems like an odd syntax for pickling. Does the package support the
normal pickle machinery? That is, does it register the appropriate
methods with the copy_reg module?

STeVe
 
K

Kay Schluehr

Kay said:
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
(!) [snip]
pickler = GeneratorPickler("test.pkl")
pickler.pickle_generator(g_gen)
k_gen = pickler.unpickle_generator()
list(g_gen) == list(k_gen)
True

This seems like an odd syntax for pickling. Does the package support the
normal pickle machinery? That is, does it register the appropriate
methods with the copy_reg module?

STeVe

The picklegenerators module defines two functions: pickle_generator
that wraps the generator into a GeneratorSnapshot object and
unpickle_generator that calls copy_generator on the unpickled
GeneratorSnapshot. The only reason I also created the GeneratorPickler
class was some simplification of testing. So I didn't invest time yet
keeping the API in line with Pythons normal pickle machinery but will
do so as the project advances i.e. in the next release.

Kay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top