python persistence

7stud bbxx789_05ss at yahoo.com
Tue Apr 1 02:14:51 CEST 2008


On Mar 31, 5:31 pm, castiro... at gmail.com wrote:
> Can you have a Python object stored entirely on disk?

import cPickle as cp

class Dog(object):
    def __init__(self, name):
        self.name = name

d = Dog("Spot")

f = open("data.txt", "w")
cp.dump(d, f)
f.close()

f = open("data.txt")
stored_obj = cp.load(f)
print stored_obj.name

--output:--
Spot



More information about the Python-list mailing list