ANN: generator_tools-0.1 released

Discussion in 'Python' started by Kay Schluehr, Oct 9, 2007.

  1. Kay Schluehr

    Kay Schluehr Guest

    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
    Kay Schluehr, Oct 9, 2007
    #1
    1. Advertising

  2. Kay Schluehr wrote:
    > 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
    Steven Bethard, Oct 9, 2007
    #2
    1. Advertising

  3. Kay Schluehr

    Kay Schluehr Guest

    On Oct 9, 7:17 pm, Steven Bethard <> wrote:
    > Kay Schluehr wrote:
    > > 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
    Kay Schluehr, Oct 9, 2007
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom Hawkins

    [ANN] Confluence 0.7.1 Released

    Tom Hawkins, Oct 23, 2003, in forum: VHDL
    Replies:
    0
    Views:
    485
    Tom Hawkins
    Oct 23, 2003
  2. Tom Hawkins

    [ANN] InFormal 0.1.1 Released

    Tom Hawkins, Nov 9, 2004, in forum: VHDL
    Replies:
    2
    Views:
    471
    Tom Hawkins
    Nov 9, 2004
  3. Jussi Jumppanen

    ANN: Zeus Version 3.95 Editor Released

    Jussi Jumppanen, Aug 8, 2005, in forum: VHDL
    Replies:
    0
    Views:
    419
    Jussi Jumppanen
    Aug 8, 2005
  4. Al Ponomarev
    Replies:
    3
    Views:
    453
    Ken Cox [Microsoft MVP]
    May 3, 2004
  5. Lei Yang
    Replies:
    0
    Views:
    322
    Lei Yang
    Oct 8, 2005
Loading...

Share This Page