I need to program a way of storing and deleting multiple objects so that they stay around even after the program has been closed and that when you re-start the program you can search for an object?

I'am using python 3.0 not 2.7.

i.e. I create A class with different Variables, I initialise it with an object and the next time I use my program I can search for the stored object and all its variables.

Recommended Answers

All 8 Replies

check out the pickle module (I think it still is used with v3.x)

Ya, pickle will allow you to save your classes to disk. Once you close python, objects are removed from memory so it doesn't make much sense to talk about restoring unless you've saved it to your harddisk.

Ya, pickle will allow you to save your classes to disk. Once you close python, objects are removed from memory so it doesn't make much sense to talk about restoring unless you've saved it to your harddisk.

I've Tried Pickling objects But how do I then Recover Multiple Objects becasue If I store more than one object from the same class it only returns the first object?

A dictionary is also a good way to pickle multiple instances so that you can look them up by some sort of logical key.

If you want to use a dictionary, you might as well use Python module shelve and create a 'persistent to file' dictionary.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.