List to Text back to List
clp at rebertia.com
Thu Nov 6 21:33:41 CET 2008
On Thu, Nov 6, 2008 at 12:18 PM, SimonPalmer <simon.palmer at gmail.com> wrote:
> On Nov 6, 8:11 pm, "Chris Rebert" <c... at rebertia.com> wrote:
>> On Thu, Nov 6, 2008 at 12:04 PM, SimonPalmer <simon.pal... at gmail.com> wrote:
>> > Hi, I am looking for a way to convert a List of floating point numbers
>> > to and from text. I am embedding it in an XML document and am looking
>> > for a neat way to serialise and de-serialise a list from a text node.
>> > I can easily write something to do it manually but I wondered whether
>> > List had native support to go to and from text.
>> > If not List, are there any other collections/arrays that do this?
>> It's not really a matter of the collection, but more a matter of
>> serialization format/library.
>> If you want the serialized representation to be human-readable, use
>> JSON (http://docs.python.org/library/json.html#module-json).
>> If that's not a requirement, use pickle
>> Both modules can convert simple Python data, such as your list of
>> floats, to a bytestream and back again.
>> Follow the path of the Iguana...http://rebertia.com
>> > TIA
>> > Simon
>> > --
> I looked at pickle, but the problem is that I want my XML to be
> readable by languages other than python, so it sort of precludes it.
> JSON would be perfect, but I think the module only exists in 2.6, is
> that right? Unfortunately I am bound to 2.4.
> It is looking more and more like I am going to have to roll my own.
The module is available as a third-party library for previous Python
versions at http://www.undefined.org/python/
Follow the path of the Iguana...
More information about the Python-list