Skip to content Skip to sidebar Skip to footer

Can A Python Generator Be Easily Saved And Reloaded From Disk?

Is there a way to serialize a generator, current state and all (local variables, etc), so that you can load the string containing the serialized generator later and be able to pick

Solution 1:


Solution 2:

Stackless Python is able to pickle generators. Or you could try PyPy 1.7, which also implements many stackless features, including pickling of generators and functions.

Code snippet: http://pastebin.com/p4RkVQkJ

Stackless Python 3.2 and 2.7.2 could be downloaded here: http://zope.stackless.com/download/sdocument_view

PyPy 1.7 could be downloaded here: http://pypy.org/download.html


Post a Comment for "Can A Python Generator Be Easily Saved And Reloaded From Disk?"