views:

55

answers:

3

I cannot understand it. Very simple, and obvious functionality: You have a code in any programming language, You run it. In this code You generate variables, than You save them (the values, names, namely everything) to a file, with one command. When it's saved You may open such a file in Your code also with simple command. It works perfect in matlab (save Workspace , load Workspace ) - in python there's some weird "pickle" protocol, which produces errors all the time, while all I want to do is save variable, and load it again in another session (?????) f.e. You cannot save class with variables (in Matlab there's no problem) You cannot load arrays in cPickle (but YOu can save them (?????) ) Why don't make it easier? Is there a way to save the current variables with values, and then load them?

+1  A: 

What you are describing is Matlab environment feature not a programming language. What you need is a way to store serialized state of some object which could be easily done in almost any programming language. In python world pickle is the easiest way to achieve it and if you could provide more details about the errors it produces for you people would probably be able to give you more details on that. In general for object oriented languages (including python) it is always a good approach to incapsulate a your state into single object that could be serialized and de-serialized and then store/load an instance of such class. Pickling and unpickling of such objects works perfectly for many developers so this must be something specific to your implementation.

Alexander Finn
Thanks for the reply. cPickle works fine with simple variables, but I've a big database of say 50mb. What goes wrong I've described here http://stackoverflow.com/questions/3004792/cpickle-importerror-no-module-named-multiarray - I didn't get the answer unfortunately, so I'm stuck. I need to save lists and when I do it it doesn't load, because of this error. So I'm searching another way.
Rafal
it seems that your problem is not related to Pickle but rather to some library your code is implicitly relying on. I'll try to reply you in the original thread with my ideas but it certainly has nothing to do with pickle although pickling (or serializing in general) large datasets (50mb is a huge data set for serialization) is not a good idea and you may need to look into alternatives. May be you need to look into document storages like MongoDB or CouchDB to store your data in JSON format?
Alexander Finn
+1  A: 

PiCloud has implemented a fancier pickle, but I can't find the code. I saw a poster session.

Generally in Python instantiated objects don't have any one way to recreate them, and in some cases its particularly difficult (like an open file) as it takes several steps to recreate.

Ian Bicking
A: 

Since you're talking about Matlab, you probably want to try out IPython, which is a shell for Python offering much more functionality than the standard interpreter shell you get when executing Python.

Among this functionality is the ability to load/save workspace sessions, create macros out of session input etc., which is probably more like what you are used to in Matlab (I actually use both and find IPython to be much more elegant, but YMMV):

http://ipython.scipy.org

Jim