By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,767 Members | 1,987 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,767 IT Pros & Developers. It's quick & easy.

Save/Store whole class (or another object) in a file

P: n/a
Hi,

is it possible in python (with/without matplotlib, numpy etc) to store
a whole class with its data into a file, instead it to reconstruct
every time again? So is there an analogous to the matlab functions
load/save available?

Thanks
Alex

Oct 17 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
is it possible in python (with/without matplotlib, numpy etc) to store
a whole class with its data into a file, instead it to reconstruct
every time again? So is there an analogous to the matlab functions
load/save available?
look up the pickle module.

Oct 17 '06 #2

P: n/a
al******@googlemail.com enlightened us with:
is it possible in python (with/without matplotlib, numpy etc) to
store a whole class with its data into a file
Check out the pickle module.

Sybren
--
Sybren Stüvel
Stüvel IT - http://www.stuvel.eu/
Oct 17 '06 #3

P: n/a
Hi,

thanks for the reply,but unfortunately this does not work with the type
of classes I am dealing with. When trying to pickle the class I get the
following error:

File "/usr/lib/python2.4/copy_reg.py", line 76, in _reduce_ex
raise TypeError("a class that defines __slots__ without "
TypeError: a class that defines __slots__ without defining __getstate__
cannot be pickled

So there is something missing in this class? Or any other idea how to
do this?

Alex
Sybren Stuvel wrote:
al******@googlemail.com enlightened us with:
is it possible in python (with/without matplotlib, numpy etc) to
store a whole class with its data into a file

Check out the pickle module.

Sybren
--
Sybren Stvel
Stvel IT - http://www.stuvel.eu/
Oct 18 '06 #4

P: n/a
al******@googlemail.com wrote:
thanks for the reply,but unfortunately this does not work with the type
of classes I am dealing with. When trying to pickle the class I get the
following error:

File "/usr/lib/python2.4/copy_reg.py", line 76, in _reduce_ex
raise TypeError("a class that defines __slots__ without "
TypeError: a class that defines __slots__ without defining __getstate__
cannot be pickled

So there is something missing in this class?
did you remember to read the error message before posting ?

</F>

Oct 18 '06 #5

P: n/a
al******@googlemail.com wrote:
Hi,

thanks for the reply,but unfortunately this does not work with the type
of classes I am dealing with. When trying to pickle the class I get the
following error:

File "/usr/lib/python2.4/copy_reg.py", line 76, in _reduce_ex
raise TypeError("a class that defines __slots__ without "
TypeError: a class that defines __slots__ without defining __getstate__
cannot be pickled

So there is something missing in this class? Or any other idea how to
do this?

Alex
yes, read the documentation:
http://docs.python.org/dev/lib/pickle-inst.html

Michele Simionato

Oct 18 '06 #6

P: n/a
Hi,

Fredrik Lundh wrote:
al******@googlemail.com wrote:
thanks for the reply,but unfortunately this does not work with the type
of classes I am dealing with. When trying to pickle the class I get the
following error:

File "/usr/lib/python2.4/copy_reg.py", line 76, in _reduce_ex
raise TypeError("a class that defines __slots__ without "
TypeError: a class that defines __slots__ without defining __getstate__
cannot be pickled

So there is something missing in this class?

did you remember to read the error message before posting ?
of course I read the error-message, I understand the error-message, BUT
this message is not telling me how anyway to save the data of such a
class in a file! It does not tell me, that there is absolutely no way
to do that. Maybe there is, maybe there is not.
Thats why I am posting it here!

Alex

Oct 25 '06 #7

P: n/a
At Wednesday 25/10/2006 11:32, al******@googlemail.com wrote:
>Fredrik Lundh wrote:
al******@googlemail.com wrote:
thanks for the reply,but unfortunately this does not work with the type
of classes I am dealing with. When trying to pickle the class I get the
following error:
>
File "/usr/lib/python2.4/copy_reg.py", line 76, in _reduce_ex
raise TypeError("a class that defines __slots__ without "
TypeError: a class that defines __slots__ without defining __getstate__
cannot be pickled
>
So there is something missing in this class?
did you remember to read the error message before posting ?

of course I read the error-message, I understand the error-message, BUT
this message is not telling me how anyway to save the data of such a
class in a file! It does not tell me, that there is absolutely no way
to do that. Maybe there is, maybe there is not.
Thats why I am posting it here!
"A man who wears a hat without buying a ticket cannot enter the theatre"
You wear a hat, you want to enter: either buy your ticket or forget
about your hat.
In this case, just define a __getstate__ method (read the pickle
docs), or forget about __slots__.
--
Gabriel Genellina
Softlab SRL

__________________________________________________
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam gratis!
Abr tu cuenta ya! - http://correo.yahoo.com.ar
Oct 25 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.