Re: Pickle file and send via socket

2022-02-18 Thread Chris Angelico
On Sat, 19 Feb 2022 at 05:47, UTKARSH PANDEY wrote: > > On Wednesday, August 8, 2012 at 8:37:33 PM UTC+5:30, lipska the kat wrote: > > ... > Directly read bytes from file and send it over the socket object from client > side in while loop until all content from file is read. > Almost ten years.

Re: Pickle file and send via socket

2022-02-18 Thread UTKARSH PANDEY
On Wednesday, August 8, 2012 at 8:37:33 PM UTC+5:30, lipska the kat wrote: > On 08/08/12 14:50, S.B wrote: > > On Wednesday, August 8, 2012 3:48:43 PM UTC+3, lipska the kat wrote: > >> On 06/08/12 14:32, S.B wrote: > >> > [snip] > > Thank you so much ! > > The examples are very helpful. > > Wh

Re: Pickle segfaults with custom type

2022-01-15 Thread Marco Sulla
Found. I simply forgot: if (PyType_Ready(&PyFrozenDictIterKey_Type) < 0) { goto fail; } in the frozendict_exec function for the module. On Fri, 7 Jan 2022 at 20:27, Marco Sulla wrote: > I have a custom implementation of dict using a C extension. All works but > the pickling of

Re: Pickle in C does not work

2020-10-20 Thread Serhiy Storchaka
20.10.20 17:12, Marco Sulla пише: > On Tue, 20 Oct 2020 at 16:07, Serhiy Storchaka wrote: >> You can use PyDict_New() + PyDict_Merge() to create a dict from your >> mapping. > Well, yes, I know. I just wrote it for simplicity now. Do you think this is > the problem? I think that it can be more pe

Re: Pickle in C does not work

2020-10-20 Thread Marco Sulla
On Tue, 20 Oct 2020 at 16:12, Marco Sulla wrote: > tp_name of your class should include the module name. >> > > It will be done :-) > It was the name... Thank you a lot! -- https://mail.python.org/mailman/listinfo/python-list

Re: Pickle in C does not work

2020-10-20 Thread Marco Sulla
On Tue, 20 Oct 2020 at 16:07, Serhiy Storchaka wrote: > You can use PyDict_New() + PyDict_Merge() to create a dict from your > mapping. > Well, yes, I know. I just wrote it for simplicity now. Do you think this is the problem? I forgot to say that copy and deepcopy works. For what I know, they u

Re: Pickle in C does not work

2020-10-20 Thread Serhiy Storchaka
20.10.20 01:28, Marco Sulla пише: > PyObject *d = PyObject_Call((PyObject *)&PyDict_Type, args, NULL); You can use PyDict_New() + PyDict_Merge() to create a dict from your mapping. > but I get: > _pickle.PicklingError: Can't pickle : attribute lookup > frozendict on builtins failed tp_name o

Re: Pickle caching objects?

2019-12-16 Thread Peter J. Holzer
On 2019-12-16 08:56:26 +0100, dieter wrote: > Note also that Python memeory management is quite elaborate: > not every memory block is immediately obtained from and released > to the operating system: Python has its own memory management > data structures (to fill the gap between the fine grained >

Re: Pickle caching objects?

2019-12-16 Thread Inada Naoki
Would you try the pull request in this issue? https://bugs.python.org/issue36694 I'm not sure this issue is relating to you because I don't know about your data. Regards, On Sun, Dec 1, 2019 at 10:14 AM José María Mateos wrote: > > Hi, > > I just asked this question on the IRC channel but didn'

Re: Pickle caching objects?

2019-12-15 Thread dieter
José María Mateos writes: > I just asked this question on the IRC channel but didn't manage to get > a response, though some people replied with suggestions that expanded > this question a bit. > > I have a program that has to read some pickle files, perform some > operations on them, and then ret

Re: Pickle caching objects?

2019-12-01 Thread José María Mateos
On Sun, Dec 01, 2019 at 12:26:15PM +1100, Chris Angelico wrote: I can't answer your question authoritatively, but I can suggest a place to look. Python's memory allocator doesn't always return memory to the system when the objects are freed up, for various reasons including the way that memory pa

Re: Pickle caching objects?

2019-11-30 Thread Richard Damon
On 11/30/19 5:05 PM, José María Mateos wrote: > Hi, > > I just asked this question on the IRC channel but didn't manage to get > a response, though some people replied with suggestions that expanded > this question a bit. > > I have a program that has to read some pickle files, perform some > opera

Re: Pickle caching objects?

2019-11-30 Thread Chris Angelico
On Sun, Dec 1, 2019 at 12:15 PM José María Mateos wrote: > print("Memory usage:", psutil.Process(os.getpid()).memory_info().rss) > > Notice that memory usage increases noticeably specially on files 4 and > 5, the biggest ones, and doesn't come down as I would expect it to. But > the loadin

Re: Pickle failed __getstate__ on my customized class inherited dict

2019-11-20 Thread Peter Otten
lampahome wrote: > I make a class Wrapper inherited from dict and met problem when I want to > pickle it. > > Is there anyway to make __getstate__ of Wrapper to output a normal > dict?(Output a dict will help pickleing easily) > > > === code === > import pickle > class Wrapper(dict): > def

Re: Pickle failed __getstate__ on my customized class inherited dict

2019-11-19 Thread dieter
lampahome writes: > I make a class Wrapper inherited from dict and met problem when I want to > pickle it. > > Is there anyway to make __getstate__ of Wrapper to output a normal > dict?(Output a dict will help pickleing easily) > > > === code === > import pickle > class Wrapper(dict): > def __

Re: pickle and module versioning

2018-12-18 Thread dieter
Neal Becker writes: > ... > Has anyone else run into this issue People who use the "ZODB" (= "Zope Object DataBase") are familiar with it. > and have any ideas? There are things, you must not do. In the "ZODB" case, for example, you must not change whether the class inherits from "persistent.Pe

Re: pickle and module versioning

2018-12-17 Thread Peter Otten
Neal Becker wrote: > I find pickle really handy for saving results from my (simulation) > experiments. But recently I realized there is an issue. Reading the > saved results requires loading the pickle, which in turn will load any > referenced > modules. Problem is, what if the modules have cha

RE: pickle and module versioning

2018-12-17 Thread Calvin Spealman
This can definitely be a problem, but there are tried and true strategies to deal with it and the best course of action depends a lot on what works for you. Pickle deserialization is just an API instantiating your class instances. That means all the same rules and approaches to API changes apply

Re: Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172

2016-03-10 Thread dieter
"Veek. M" writes: > ... > what i wanted to know was, x = Client('192.168.0.1') will create an > object 'x' with the IP inside it. When I do: > pickle.dump(x) > pickle doesn't know where in the object the IP is, so he'll call > __getstate__ and expect the return value to be the IP, right? It doe

Re: Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172

2016-03-09 Thread Veek. M
Ian Kelly wrote: > On Wed, Mar 9, 2016 at 2:14 AM, Veek. M wrote: >> what i wanted to know was, x = Client('192.168.0.1') will create an >> object 'x' with the IP inside it. When I do: >> pickle.dump(x) >> pickle doesn't know where in the object the IP is, so he'll call >> __getstate__ and expect

Re: Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172

2016-03-09 Thread Ian Kelly
On Wed, Mar 9, 2016 at 2:14 AM, Veek. M wrote: > what i wanted to know was, x = Client('192.168.0.1') will create an > object 'x' with the IP inside it. When I do: > pickle.dump(x) > pickle doesn't know where in the object the IP is, so he'll call > __getstate__ and expect the return value to be t

Re: Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172

2016-03-09 Thread Veek. M
dieter wrote: > "Veek. M" writes: > >> import socket >> class Client(object): >> def __init__(self,addr): >> self.server_addr = addr >> self.sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) >> self.sock.connect(addr) >> >> def __getstate__(self): >> return self.server_addr >>

Re: Pickle __getstate__ __setstate__ and restoring n/w - beazley pg 172

2016-03-09 Thread dieter
"Veek. M" writes: > import socket > class Client(object): > def __init__(self,addr): > self.server_addr = addr > self.sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM) > self.sock.connect(addr) > > def __getstate__(self): > return self.server_addr > > def __setstate__(self,valu

Re: Pickle based workflow - looking for advice

2015-04-14 Thread Chris Angelico
On Wed, Apr 15, 2015 at 12:14 AM, Steven D'Aprano wrote: > On Tue, 14 Apr 2015 11:45 pm, Chris Angelico wrote: > >> On Tue, Apr 14, 2015 at 11:08 PM, Steven D'Aprano >> wrote: >>> On Tue, 14 Apr 2015 05:58 pm, Fabien wrote: >>> On 14.04.2015 06:05, Chris Angelico wrote: > Not sure what y

Re: Pickle based workflow - looking for advice

2015-04-14 Thread Steven D'Aprano
On Tue, 14 Apr 2015 11:45 pm, Chris Angelico wrote: > On Tue, Apr 14, 2015 at 11:08 PM, Steven D'Aprano > wrote: >> On Tue, 14 Apr 2015 05:58 pm, Fabien wrote: >> >>> On 14.04.2015 06:05, Chris Angelico wrote: Not sure what you mean, here. Any given file will be written by exactly one p

Re: Pickle based workflow - looking for advice

2015-04-14 Thread Chris Angelico
On Tue, Apr 14, 2015 at 11:08 PM, Steven D'Aprano wrote: > On Tue, 14 Apr 2015 05:58 pm, Fabien wrote: > >> On 14.04.2015 06:05, Chris Angelico wrote: >>> Not sure what you mean, here. Any given file will be written by >>> exactly one process? No possible problem. Multiprocessing within one >>> ap

Re: Pickle based workflow - looking for advice

2015-04-14 Thread Steven D'Aprano
On Tue, 14 Apr 2015 05:58 pm, Fabien wrote: > On 14.04.2015 06:05, Chris Angelico wrote: >> Not sure what you mean, here. Any given file will be written by >> exactly one process? No possible problem. Multiprocessing within one >> application doesn't change that. > > yes that's what I meant. Than

Re: Pickle based workflow - looking for advice

2015-04-14 Thread Fabien
On 14.04.2015 06:05, Chris Angelico wrote: Not sure what you mean, here. Any given file will be written by exactly one process? No possible problem. Multiprocessing within one application doesn't change that. yes that's what I meant. Thanks! -- https://mail.python.org/mailman/listinfo/python-li

Re: Pickle based workflow - looking for advice

2015-04-13 Thread Chris Angelico
On Tue, Apr 14, 2015 at 3:35 AM, Fabien wrote: > With multiprocessing, do I have to care about processes writing > simultaneously in *different* files? I guess the OS takes good care of this > stuff but I'm not an expert. Not sure what you mean, here. Any given file will be written by exactly one

Re: Pickle based workflow - looking for advice

2015-04-13 Thread Fabien
On 13.04.2015 19:08, Peter Otten wrote: How about a file-based workflow? Write distinct scripts, e. g. a2b.py that reads from *.a and writes to *.b and so on. Then use a plain old makefile to define the dependencies. Whether .a uses pickle, .b uses json, and .z uses csv is but an implementatio

Re: Pickle based workflow - looking for advice

2015-04-13 Thread Fabien
On 13.04.2015 17:45, Devin Jeanpierre wrote: On Mon, Apr 13, 2015 at 10:58 AM, Fabien wrote: >Now, to my questions: >1. Does that seem reasonable? A big issue is the use of pickle, which is: * Often suboptimal performance wise (e.g. you can't load only subsets of the data) * Makes forwards/ba

Re: Pickle based workflow - looking for advice

2015-04-13 Thread Fabien
On 13.04.2015 18:25, Dave Angel wrote: On 04/13/2015 10:58 AM, Fabien wrote: Folks, A comment. Pickle is a method of creating persistent data, most commonly used to preserve data between runs. A database is another method. Although either one can also be used with multiprocessing, you seem

Re: Pickle based workflow - looking for advice

2015-04-13 Thread Peter Otten
Fabien wrote: > I am writing a quite extensive piece of scientific software. Its > workflow is quite easy to explain. The tool realizes series of > operations on watersheds (such as mapping data on it, geostatistics and > more). There are thousands of independent watersheds of different size, > an

Re: Pickle based workflow - looking for advice

2015-04-13 Thread Dave Angel
On 04/13/2015 10:58 AM, Fabien wrote: Folks, A comment. Pickle is a method of creating persistent data, most commonly used to preserve data between runs. A database is another method. Although either one can also be used with multiprocessing, you seem to be worrying more about the mechan

Re: Pickle based workflow - looking for advice

2015-04-13 Thread Robin Becker
for what it's worth I believe that marshal is a faster method for storing simple python objects. So if your information can be stored using simple python things eg strings, floats, integers, lists and dicts then storage using marshal is faster than pickle/cpickle. If you want to persist the obje

Re: Pickle based workflow - looking for advice

2015-04-13 Thread Devin Jeanpierre
On Mon, Apr 13, 2015 at 10:58 AM, Fabien wrote: > Now, to my questions: > 1. Does that seem reasonable? A big issue is the use of pickle, which is: * Often suboptimal performance wise (e.g. you can't load only subsets of the data) * Makes forwards/backwards compatibility very difficult * Can mak

Re: pickle error by multiprocessing

2015-02-19 Thread perfectican
I guess, The issue is not caused by multiprocessing. make sure you are pickling right object that can be pickable or not. Best way is run it in a console and test at which object the pickling error is occurring and then try to change the object which could be pickable. -- https://mail.python.or

Re: pickle error by multiprocessing

2015-02-15 Thread Albert-Jan Roskam
On Sun, Feb 15, 2015 7:43 AM CET dieter wrote: >Martijn Millecamp writes: > >> for a schoolproject we had to build a robot and control this robot with a >> gui to follow a pathWe use multiprocessingand in our group 2 people can run >> the codebut if i run the code,

Re: pickle error by multiprocessing

2015-02-14 Thread dieter
Martijn Millecamp writes: > for a schoolproject we had to build a robot and control this robot with a gui > to follow a pathWe use multiprocessingand in our group 2 people can run the > codebut if i run the code, i got a pickle errorI have a windows 7 and use > python 2.7 just like the othersW

Re: pickle error by multiprocessing

2015-02-14 Thread Tim Golden
On 14/02/2015 13:19, Martijn Millecamp wrote: for a schoolproject we had to build a robot and control this robot with a gui to follow a path We use multiprocessing and in our group 2 people can run the code but if i run the code, i got a pickle error I have a windows 7 and use python 2.7 just lik

Re: pickle and then object changes

2015-01-20 Thread Peter Otten
James Smith wrote: > Say an object like this exists: > class test: > a = "" > b = "" > > You pickle it. > > You change the object definition to have a new field: > class test > a = "" > b = "" > c = "" > > You read the pickled object. > Will it load but ignore the new field?

Re: pickle, modules, and ImportErrors

2015-01-07 Thread Chris Angelico
On Thu, Jan 8, 2015 at 11:23 AM, John Ladasky wrote: >> P.S. don't use pickle, it is a security vulnerability equivalent in >> severity to using exec in your code, and an unversioned opaque >> schemaless blob that is very difficult to work with when circumstances >> change. > > For all of its shor

Re: pickle, modules, and ImportErrors

2015-01-07 Thread John Ladasky
On Wednesday, January 7, 2015 12:56:29 PM UTC-8, Devin Jeanpierre wrote: [snip] > If you never run model directly, and only ever import it or run it as > my_svr.model, then you will be fine, and pickles will all serialize > and deserialize the same way. Thank you Devin... I re-ran TrainingSessio

Re: pickle, modules, and ImportErrors

2015-01-07 Thread Ian Kelly
On Wed, Jan 7, 2015 at 1:12 PM, John Ladasky wrote: > Do I need to "import my_svr.model as model" then? Adding that line changes > nothing. I get the exact same "ImportError: No module named 'model'". > > Likewise for "import my_svr", "from my_svr import *", or even "from > my_svr.model import

Re: pickle, modules, and ImportErrors

2015-01-07 Thread Devin Jeanpierre
On Wed, Jan 7, 2015 at 2:12 PM, John Ladasky wrote: > If I execute "import my_svr" in an iPython interpreter, everything works as I > think that I should expect: -snip- > However, a nearly-identical program in the parent folder fails (note that all > I change is the relative path to the file): >

Re: Pickle virtual machines implemented in other languages?

2013-10-29 Thread Ned Batchelder
On 10/29/13 12:12 PM, Patrick wrote: Hi Everyone I was just wondering if anyone had tried to implement a pickle virtual machine in another language? I was thinking that it might make for a nice little form of cross language IPC within a trusted environment. Pickle can execute class constru

Re: pickle module doens't work

2013-01-02 Thread Omer Korat
Yeah, right. I didn't think about that. I'll check in the source how the data is stored. Thanks for helping sort it all out. -- http://mail.python.org/mailman/listinfo/python-list

Re: pickle module doens't work

2013-01-01 Thread Tim Roberts
Omer Korat wrote: > >I am using the nltk.classify.MaxEntClassifier. This object has a set of >labels, and a set of probabilities: P(label | features). It modifies >this probability given data. SO for example, if you tell this object >that the label L appears 60% of the time with the feature F,

Re: pickle module doens't work

2013-01-01 Thread Omer Korat
I am using the nltk.classify.MaxEntClassifier. This object has a set of labels, and a set of probabilities: P(label | features). It modifies this probability given data. SO for example, if you tell this object that the label L appears 60% of the time with the feature F, then P(L | F) = 0.6. The

Re: pickle module doens't work

2012-12-28 Thread Tim Roberts
Omer Korat wrote: > >So it means pickle doesn't ever save the object's values, only how it was >created? You say that as though there were a difference between the two. There isn't. An object is just a dictionary of values. If you set an object member to a string, then that object's dictiona

Re: pickle module doens't work

2012-12-27 Thread Terry Reedy
On 12/27/2012 7:34 AM, Dave Angel wrote: Perhaps you'd rather see it in the Python docs. http://docs.python.org/2/library/pickle.html http://docs.python.org/3.3/library/pickle.html pickle can save and restore class instances transpare

Re: pickle module doens't work

2012-12-27 Thread Chris Angelico
On Fri, Dec 28, 2012 at 12:16 AM, Omer Korat wrote: > I see. In that case, all I have to do is make sure NLTK is available when I > load the pickled objects. That pretty much solves my problem. Thanks! > So it means pickle doesn't ever save the object's values, only how it was > created? > > Say

Re: pickle module doens't work

2012-12-27 Thread Omer Korat
I see. In that case, all I have to do is make sure NLTK is available when I load the pickled objects. That pretty much solves my problem. Thanks! So it means pickle doesn't ever save the object's values, only how it was created? Say I have a large object that requires a lot of time to train on

Re: pickle module doens't work

2012-12-27 Thread Dave Angel
On 12/27/2012 07:05 AM, Omer Korat wrote: > You're probably right in general, for me the 3.3 and 2.7 pickles definitely > don't work the same: > > 3.3: type(pickle.dumps(1)) > > > 2.7: type(pickle.dumps(1, pickle.HIGHEST_PROTOCOL)) > That is the same. In 2.7, str is made up of bytes,

Re: pickle module doens't work

2012-12-27 Thread Omer Korat
You're probably right in general, for me the 3.3 and 2.7 pickles definitely don't work the same: 3.3: >>> type(pickle.dumps(1)) 2.7: >>> type(pickle.dumps(1, pickle.HIGHEST_PROTOCOL)) As you can see, in 2.7 when I try to dump something, I get useless string. Look what I gen when I dump an N

Re: pickle module doens't work

2012-12-27 Thread Peter Otten
Omer Korat wrote: > I'm working on a project in Python 2.7. I have a few large objects, and I > want to save them for later use, so that it will be possible to load them > whole from a file, instead of creating them every time anew. It is > critical that they be transportable between platforms. P

Re: Pickle file and send via socket

2012-08-08 Thread Oscar Benjamin
On 8 August 2012 16:07, lipska the kat wrote: > On 08/08/12 14:50, S.B wrote: > >> On Wednesday, August 8, 2012 3:48:43 PM UTC+3, lipska the kat wrote: >> >>> On 06/08/12 14:32, S.B wrote: >>> >>> > [snip] > > > Thank you so much ! >> The examples are very helpful. >> What happens if I have a re

Re: Pickle file and send via socket

2012-08-08 Thread lipska the kat
On 08/08/12 14:50, S.B wrote: On Wednesday, August 8, 2012 3:48:43 PM UTC+3, lipska the kat wrote: On 06/08/12 14:32, S.B wrote: [snip] Thank you so much ! The examples are very helpful. What happens if I have a regular text file I want to send via the network. Do I need to read the file an

Re: Pickle file and send via socket

2012-08-08 Thread S.B
On Wednesday, August 8, 2012 3:48:43 PM UTC+3, lipska the kat wrote: > On 06/08/12 14:32, S.B wrote: > > > Hello friends > > > > > > Does anyone know if it's possible to pickle and un-pickle a file across a > > network socket. i.e: > > > First host pickles a file object and writes the pickled

Re: Pickle file and send via socket

2012-08-08 Thread lipska the kat
On 06/08/12 14:32, S.B wrote: Hello friends Does anyone know if it's possible to pickle and un-pickle a file across a network socket. i.e: First host pickles a file object and writes the pickled file object to a client socket. Second host reads the pickled file object from the server socket an

Re: Pickle file and send via socket

2012-08-07 Thread lipska the kat
On 07/08/12 12:21, S.B wrote: Can anyone provide a simple code example of the client and server sides? Working on it lipska -- Lipska the Kat: Troll hunter, sandbox destroyer and farscape dreamer of Aeryn Sun -- http://mail.python.org/mailman/listinfo/python-list

Re: Pickle file and send via socket

2012-08-07 Thread S.B
On Monday, August 6, 2012 4:32:13 PM UTC+3, S.B wrote: > Hello friends > > > > Does anyone know if it's possible to pickle and un-pickle a file across a > network socket. i.e: > > First host pickles a file object and writes the pickled file object to a > client socket. > > Second host reads

Re: Pickle file and send via socket

2012-08-06 Thread Christian Heimes
Am 06.08.2012 15:32, schrieb S.B: > Does anyone know if it's possible to pickle and un-pickle a file across a > network socket. i.e: > First host pickles a file object and writes the pickled file object to a > client socket. > Second host reads the pickled file object from the server socket and

Re: Pickle file and send via socket

2012-08-06 Thread Nobody
On Mon, 06 Aug 2012 06:32:13 -0700, S.B wrote: > Does anyone know if it's possible to pickle and un-pickle a file across > a network socket. i.e: First host pickles a file object and writes the > pickled file object to a client socket. Second host reads the pickled > file object from the server so

Re: Pickle file and send via socket

2012-08-06 Thread Ramchandra Apte
You can use pickle.dumps and pickle.loads On 6 August 2012 19:17, Ramchandra Apte wrote: > This is *absolutely* possible. > Did you know that IDLE uses this very method when run i

Re: Pickle file and send via socket

2012-08-06 Thread Ramchandra Apte
This is *absolutely* possible. Did you know that IDLE uses this very method when run in sub-process mode! On 6 August 2012 19:02, S.B wrote: > Hello friends > > Does anyone know if it's possible to pickle and un-pickle a file across a > network socket. i.e: > First host pickles a file object and

Re: pickle question: sequencing of operations

2012-05-09 Thread Ian Kelly
On Wed, May 9, 2012 at 2:34 PM, Ian Kelly wrote: > On Wed, May 9, 2012 at 1:39 PM, Russell E. Owen wrote: >> I was wondering. I override __new__ (and __init__) to print messages and >> was quite surprised to only see __new__being called when the object was >> first created, not when it was being

Re: pickle question: sequencing of operations

2012-05-09 Thread Ian Kelly
On Wed, May 9, 2012 at 1:39 PM, Russell E. Owen wrote: > I was wondering. I override __new__ (and __init__) to print messages and > was quite surprised to only see __new__being called when the object was > first created, not when it was being unpickled. But maybe there's > something funny about my

Re: pickle question: sequencing of operations

2012-05-09 Thread Russell E. Owen
In article , Ian Kelly wrote: > On Tue, May 8, 2012 at 1:19 PM, Russell E. Owen wrote: > > In article , > >  "Russell E. Owen" wrote: > > > >> What is the sequence of calls when unpickling a class with __setstate__? > > I believe it just calls object.__new__ followed by > yourclass.__setstat

Re: pickle question: sequencing of operations

2012-05-08 Thread Ian Kelly
On Tue, May 8, 2012 at 1:19 PM, Russell E. Owen wrote: > In article , >  "Russell E. Owen" wrote: > >> What is the sequence of calls when unpickling a class with __setstate__? I believe it just calls object.__new__ followed by yourclass.__setstate__. So at the point __setstate__ is called, you

Re: pickle question: sequencing of operations

2012-05-08 Thread Russell E. Owen
In article , "Russell E. Owen" wrote: > What is the sequence of calls when unpickling a class with __setstate__? > > >From experimentation I see that __setstate__ is called and __init__ is > not, but I think I need more info. > > I'm trying to pickle an instance of a class that is a subclass

Re: pickle/unpickle class which has changed

2012-03-07 Thread Gelonida N
On 03/07/2012 09:04 AM, Peter Otten wrote: > Gelonida N wrote: > If you know in advance that your class will undergo significant changes you > may also consider storing more stable data in a file format that can easily > be modified, e. g. json. > Good point, that's what I'm partially doing. I

Re: pickle/unpickle class which has changed

2012-03-07 Thread Peter Otten
Gelonida N wrote: > Is there anyhing like a built in signature which would help to detect, > that one tries to unpickle an object whose byte code has changed? No. The only thing that is stored is the "protocol", the format used to store the data. > The idea is to distinguish old and new pickle

Re: pickle/unpickle class which has changed

2012-03-06 Thread Gelonida N
Hi Peter, A related question. Is there anyhing like a built in signature which would help to detect, that one tries to unpickle an object whose byte code has changed? The idea is to distinguish old and new pickled data and start some 'migration code' fi required The only thing, that I thought

Re: pickle/unpickle class which has changed

2012-03-06 Thread Peter Otten
Neal Becker wrote: > Peter Otten wrote: > >> Steven D'Aprano wrote: >> >>> On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: >>> What happens if I pickle a class, and later unpickle it where the class now has added some new attributes? >>> >>> Why don't you try it? >>> >>> py>

Re: pickle/unpickle class which has changed

2012-03-06 Thread Neal Becker
Peter Otten wrote: > Steven D'Aprano wrote: > >> On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: >> >>> What happens if I pickle a class, and later unpickle it where the class >>> now has added some new attributes? >> >> Why don't you try it? >> >> py> import pickle >> py> class C: >> .

Re: pickle/unpickle class which has changed

2012-03-06 Thread Peter Otten
Steven D'Aprano wrote: > On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: > >> What happens if I pickle a class, and later unpickle it where the class >> now has added some new attributes? > > Why don't you try it? > > py> import pickle > py> class C: > ... a = 23 > ... > py> c = C()

Re: pickle/unpickle class which has changed

2012-03-06 Thread Steven D'Aprano
On Tue, 06 Mar 2012 07:34:34 -0500, Neal Becker wrote: > What happens if I pickle a class, and later unpickle it where the class > now has added some new attributes? Why don't you try it? py> import pickle py> class C: ... a = 23 ... py> c = C() py> pickled = pickle.dumps(c) py> C.b = 42 #

Re: pickle/unpickle class which has changed

2012-03-06 Thread Peter Otten
Neal Becker wrote: > What happens if I pickle a class, and later unpickle it where the class > now has added some new attributes? - If the added attributes' values are immutable, provide defaults as class attributes. - Implement an appropriate __setstate__() method. The easiest would be # unte

Re: Pickle performing class instantiation ??

2012-02-28 Thread Andrew Berg
On 2/28/2012 9:54 AM, Smiley 4321 wrote: > NameError: name 'self' is not defined self is meaningless outside a class definition. You should refactor your dump, load and print code as methods inside the class definition, create an instance and call the methods on that instance. -- CPython 3.2.2 |

Re: Pickle performing class instantiation ??

2012-02-28 Thread Peter Otten
Smiley 4321 wrote: > Am I doing the right thing for - > > - Have a class > - Instantiate the class with 3 parameters > - pickle the class instance > - generate a bytestream (.pkl) using pickle.dump, simply guessing - > > as - > > --- > #!/usr/bin/python > > import pickle > > class Pickle: >

RE: Pickle performing class instantiation ??

2012-02-28 Thread Prasad, Ramit
>class Pickle: >    def __init__(self, Parameter1, Parameter2, Parameter3): >        self.PM1 = Parameter1 >        self.PM2 = Parameter2 >        self.PM3 = Parameter3 >with open('/tmp/readfile.pkl', 'wb') as f: >    pickle.dump((self.PM1, self.PM2, self.PM3), f)     >with open('/tmp/readfile.pk

Re: Pickle performing class instantiation ??

2012-02-28 Thread Smiley 4321
Am I doing the right thing for - - Have a class - Instantiate the class with 3 parameters - pickle the class instance - generate a bytestream (.pkl) using pickle.dump, simply guessing - as - --- #!/usr/bin/python import pickle class Pickle: def __init__(self, Parameter1, Parameter2, Parame

Re: pickle handling multiple objects ..

2012-02-27 Thread Ian Kelly
On Sun, Feb 26, 2012 at 6:00 AM, Chris Angelico wrote: > Additionally, you'll get a weird crash out of your program if load() > returns something other than a sequence of length 3. Remember, > everything that comes from outside your code is untrusted, even if you > think you made it just two secon

Re: pickle handling multiple objects ..

2012-02-27 Thread 88888 Dihedral
在 2012年2月26日星期日UTC+8下午9时00分31秒,Chris Angelico写道: > On Sun, Feb 26, 2012 at 11:04 PM, Peter Otten <__pete...@web.de> wrote: > > This is however a bit errorprone. If you accidentally write the loading code > > as > > > > fruit, beverages, vegetables = pickle.load(f) > > > > you'll end up drinking pot

Re: pickle handling multiple objects ..

2012-02-26 Thread Chris Angelico
On Sun, Feb 26, 2012 at 11:04 PM, Peter Otten <__pete...@web.de> wrote: > This is however a bit errorprone. If you accidentally write the loading code > as > > fruit, beverages, vegetables = pickle.load(f) > > you'll end up drinking potatoes. You mean vodka? :) Additionally, you'll get a weird cr

Re: pickle handling multiple objects ..

2012-02-26 Thread Peter Otten
Smiley 4321 wrote: > If I have a sample python code to be executed on Linux. How should I > handle multiple objects with 'pickle' as below - > > --- > #!/usr/bin/python > > import pickle > > #my_list = {'a': 'Apple', 'b': 'Mango', 'c': 'Orange', 'd': 'Pineapple'} > #my_list = ('Apple', 'Ma

Re: pickle handling multiple objects ..

2012-02-26 Thread Chris Rebert
On Sun, Feb 26, 2012 at 3:25 AM, Smiley 4321 wrote: > If I have a sample python code to be executed on Linux. How should  I handle > multiple objects with 'pickle' as below - > > --- > #!/usr/bin/python > > import pickle > > #my_list = {'a': 'Apple', 'b': 'Mango', 'c': 'Orange', 'd': 'Pineappl

Re: Pickle a list

2011-03-08 Thread Irmen de Jong
On 07-03-11 17:38, Rogerio Luz wrote: import sys import pickle class MyClass: teste = 0 nome = None lista = ["default"] def __init__(self): for reg in range(1,10): self.lista.append(reg) ^^ This probably doesn't do w

Re: Pickle a list

2011-03-07 Thread Chris Kaynor
Chris 2011/3/7 Rogério Luz > Chris, Thanks a lot for your explanation, I got it > > class MyClass: > #class variables > > teste = 0 > nome = None > lista = ["default"] > > def __init__(self): > #instance variables > self.lista = MyClass.lista # if I still wa

Re: Pickle a list

2011-03-07 Thread Chris Kaynor
On Mon, Mar 7, 2011 at 8:38 AM, Rogerio Luz wrote: > Hi All > > I'd like to pickle an object instance with all values. So I > instanciate myClass and set some values including a list with more > values (in the __init__), then dump to file. I realized that the > pickled object don't saved my new li

Re: Pickle compatibility between Python 2.7 and python 3.2

2011-02-22 Thread Michel Claveau - MVP
Hi! I am, also, very interested in the answers. Thank you for asking this question. @-salutations -- Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list

Re: Pickle in a POST/GET request give EOFError

2010-11-18 Thread Adam Tauno Williams
On Thu, 2010-11-18 at 11:22 +0100, Romaric DEFAUX wrote: > Hi again, > I try simplejson, but I have a problem. (I just replace pickle > everywhere by simplejson) > Explanation : > I "dumps" with json a list of dictionnaries into disk_list_json. > When I "loads" it, I don't get my list of dictionn

Re: Pickle in a POST/GET request give EOFError

2010-11-18 Thread Romaric DEFAUX
Hi answer to myself :) With str(unicode_string) ! Le 18/11/2010 12:23, Romaric DEFAUX a écrit : Sorry for this stupid question, but how can I convert unicode to string. I ask that because I hit an error (perhaps a bug) in mod_wsgi, and that crash the apache process : TypeError: sequence of s

Re: Pickle in a POST/GET request give EOFError

2010-11-18 Thread Romaric DEFAUX
Sorry for this stupid question, but how can I convert unicode to string. I ask that because I hit an error (perhaps a bug) in mod_wsgi, and that crash the apache process : TypeError: sequence of string values expected, value of type unicode found RuntimeError: generator ignored GeneratorExit ch

Re: Pickle in a POST/GET request give EOFError

2010-11-18 Thread Michael Ricordeau
When loading from json datas with simplejson, strings are unicode . Le Thu, 18 Nov 2010 11:22:30 +0100, Romaric DEFAUX a écrit : > Hi again, > > I try simplejson, but I have a problem. (I just replace pickle > everywhere by simplejson) > > Here's a test I did : > # python > Python 2.5.2 (r2

Re: Pickle in a POST/GET request give EOFError

2010-11-18 Thread Romaric DEFAUX
Hi again, I try simplejson, but I have a problem. (I just replace pickle everywhere by simplejson) Here's a test I did : # python Python 2.5.2 (r252:60911, Jan 20 2010, 21:48:48) [GCC 4.2.4 (Ubuntu 4.2.4-1ubuntu3)] on linux2 Type "help", "copyright", "credits" or "license" for more information

Re: Pickle in a POST/GET request give EOFError

2010-11-18 Thread Romaric DEFAUX
Thanks for the tip, I'll do that :) Le 18/11/2010 09:43, Michael Ricordeau a écrit : Hi, you can use json for passing list and dict . Pickle is dangerous . Instead of pickle.loads/pickle.dumps use json.loads and json.dumps (using stdlib json in python>= 2.6 or simplejson in python< 2.6) Rega

Re: Pickle in a POST/GET request give EOFError

2010-11-18 Thread Michael Ricordeau
Hi, you can use json for passing list and dict . Pickle is dangerous . Instead of pickle.loads/pickle.dumps use json.loads and json.dumps (using stdlib json in python >= 2.6 or simplejson in python < 2.6) Regards Le Thu, 18 Nov 2010 09:29:00 +0100, Romaric DEFAUX a écrit : > Le 17/11/201

Re: Pickle in a POST/GET request give EOFError

2010-11-18 Thread Romaric DEFAUX
Le 17/11/2010 18:52, geremy condra a écrit : On Wed, Nov 17, 2010 at 6:44 AM, Romaric DEFAUX wrote: Le 16/11/2010 17:47, Romaric DEFAUX a écrit : Hi everybody ! First time I write to this mailing list :) I started writing in python last week, that's probably why I can't understand t

  1   2   3   >