views:

62

answers:

3

Hi there,

I'm doing a project with reasonalby big DataBase. It's not a probper DB file, but a class with format as follows: DataBase.Nodes.Data=[[] for i in range(1,1000)] f.e. this DataBase is all together something like few thousands rows. Fisrt question - is the way I'm doing efficient, or is it better to use SQL, or any other "proper" DB, which I've never used actually. And the main question - I'd like to save my DataBase class with all record, and then re-open it with Python in another session. Is that possible, what tool should I use? cPickle - it seems to be only for strings, any other?

In matlab there's very useful functionality named save workspace - it saves all Your variables to a file that You can open at another session - this would be vary useful in python!

+3  A: 

Pickle (cPickle) can handle any (picklable) Python object. So as long, as you're not trying to pickle thread or filehandle or something like that, you're ok.

vartec
+2  A: 

Pickle should be able to serialise the data for you so that you can save it to file.

Alternatively if you don't need the features of a full featured RDBMS you could use a lightweight solution like SQLLite or a document store like MongoDB

Neil Aitken
+1  A: 

The Pickle.dump function is very much like matlab's save feature. You just give it an object you wish to serialize and a file-like object to write it to. See the documentation for info and examples on how to use it.

The cPickle module is just like Pickle, but it is implemented in C so it can be much faster. You should probably use cPickle.

A. Levy
Aren't most of Python's core modules and libraries written in C?
Neil Aitken
In this case, cPickle is a separate module because some features were too difficult to implement in C. A good explanation is here: http://docs.python.org/library/pickle.html#relationship-to-other-python-modules
orangeoctopus
@orange Interesting, thanks for the link
Neil Aitken
thank's for the reply, but still have some problems with Pickle - If You can help please: http://stackoverflow.com/questions/2991557/cpickle-class-with-data-save-to-file
Rafal