[IronPython] Dict convertion question

Bruce Christensen t-bruch at microsoft.com
Wed Jul 19 20:07:53 CEST 2006


We added basic support for the pickle module in beta 9
(http://docs.python.org/lib/module-pickle.html). Pickle allows you to
convert an object to a string that you can save to a file and then read
in a string and get back and object.

Here's an example of how to use it:

IronPython 1.0.60712 (Beta) on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import sys
>>> sys.path.append('c:\python24\lib')
>>> import pickle
>>> mydict = [(x,x) for x in range(2000)]
>>> output = open('dict.txt', 'wb')
>>> pickle.dump(mydict, output, protocol=2)
>>> output.close()
>>> input = open('dict.txt', 'rb')
>>> new_dict = pickle.load(input)
>>> input.close()
>>> new_dict
[(0, 0), (1, 1), (2, 2), (3, 3), (4, 4), ...

Since we just added support for this, please let us know if you run into
any problems.


-----Original Message-----
From: users-bounces at lists.ironpython.com
[mailto:users-bounces at lists.ironpython.com] On Behalf Of JoeSox
Sent: Wednesday, July 19, 2006 10:47 AM
To: Discussion of IronPython
Subject: [IronPython] Dict convertion question

I'm interested in storing a large Dict in a text file. What I am
trying to figure out what be the best way on creating the Dict from
the text file.

I see Converter.ConvertToValueType but I don't understand how to
construct the RuntimeTypeHandle to see if that would work.

But I am thinking I need to create a custom method to handle this

Does anyone else have any ideas or point me in a direction I don't see
right now?
Later, Joe
users mailing list
users at lists.ironpython.com

More information about the Ironpython-users mailing list