tags:

views:

23

answers:

1

Im writing an app using pygtk and i was wondering how would my app be able to save data on the users computer. I plan go distribute this across windows and unix. What would be the best way to go about this?

A: 

You could use the pickle module.

It serializes data, so that you can retrieve it in it's native Python form later.

It uses the file() object, so it's cross-platform, and can handle basically any object, and it is even good with custom classes. The only thing I know it cannot serialize is a function.


Short use explenation:

import pickle
# Create an object
array = [1, "foo", Exception()]
# Serialize it
pickle.dump(array, open("settings.dat", "w"))
# Unserialize it
array = pickle.load(open("settings.dat"))
new123456