unpickle to python list
Andrew Bennetts
andrew-pythonlist at puzzling.org
Mon Feb 3 07:50:25 EST 2003
On Mon, Feb 03, 2003 at 12:23:42PM +0000, Gerhard H?ring wrote:
> Thomas Guettler <zopestoller at thomas-guettler.de> wrote:
> > Hi!
> >
> > I have a pickle which contains a flat list:
> >
> > mylist=[
> > "abc",
> > "def",
> > "ghi", ...]
> >
> > Is it possible to pickle this list to python syntax? [...]
>
> Hmm. Maybe you can rip some parts out of Twisted?
>
> <quote source="http://twistedmatrix.com/documents/howto/basics">
> TAS
> Twisted contains twisted.persisted.aot, a module that supports
> serializing into Python source. This has the advantage of using
> Python's own parser and being able to later manually add Python
> code to the file.
> </quote>
Here's a demonstration:
>>> from twisted.persisted import aot
>>> print aot.jellyToSource(['abc', 'def', 'ghi'])
app=[
'abc',
'def',
'ghi',
]
The "app=" is unfortunately hard-coded atm, because that's sufficient for
Twisted's use-case for this module. It might suit the original poster
nicely.
-Andrew.
More information about the Python-list
mailing list