views:

35

answers:

2

I have instance of the my class. I want to save implementation of class with instance's pickle copy in file. After, I want to use this instance to another computer where there is no implementation of the my class. I don't want to save text of implementation manually.

How can I do this?

A: 

Use a dict instead of a class.

knutin
It's impossible. I need a class.
ufian
actually it's possible :)
MovieYoda
+1  A: 

If you don't want to copy your source code to the "other computer" then the best best is to use native data structures, i.e. dict or list or tuples etc.

Pack what ever you want to pack & store it in these data structures, then simply do this -

import pickle

def save_to_disk(data, filename):
    pickle.dump(data, open(filename, 'w'))
    return

def read_from_disk(filename):
    data = pickle.load(open(filename))
    return data

I have heard cPickle is faster then pickle

MovieYoda