473,249 Members | 1,376 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,249 software developers and data experts.

Bug in cPickle with packages and 'object' inherited class

Say you have this structure:

pna/
__init__.py
model.py
__init__.py is empty.

model.py is:
import cPickle as pickle

class A(object):
pass

def serialize():
pickle.dump(A(), open('temp.dat', 'wb'))
Now open a python interpreter on the root directory of that structure
and type:
import pna.model
pna.model.serialize()
The following exception is thrown:
Traceback (most recent call last):
File "test.py", line 2, in <module>
pna.model.serialize()
File "...\pna\model.py", line 7, in serialize
pickle.dump(A(), open('temp.dat', 'wb'))
cPickle.PicklingError: Can't pickle <class 'pna.model.A'>: import of
module pna.model failed
If you use 'pickle' instead of 'cPickle', it works.
If you don't inherit from 'object' in 'A', it works.

I'm using Python 2.5.1 on Windows XP. I've tested in Python 2.4.4 on
Linux and it works.

Any ideas of what is going on?

Thanks,
Conrado

Jul 25 '07 #1
1 1296
En Wed, 25 Jul 2007 17:32:46 -0300, Conrado PLG <co********@gmail.com>
escribió:
Say you have this structure:

pna/
__init__.py
model.py
__init__.py is empty.

model.py is:
import cPickle as pickle

class A(object):
pass

def serialize():
pickle.dump(A(), open('temp.dat', 'wb'))
Now open a python interpreter on the root directory of that structure
and type:
import pna.model
pna.model.serialize()
The following exception is thrown:
Traceback (most recent call last):
File "test.py", line 2, in <module>
pna.model.serialize()
File "...\pna\model.py", line 7, in serialize
pickle.dump(A(), open('temp.dat', 'wb'))
cPickle.PicklingError: Can't pickle <class 'pna.model.A'>: import of
module pna.model failed
It works for me. What are those "..." in the file name?

--
Gabriel Genellina

Jul 30 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Guenter Walser | last post by:
Hello, When using the codeline: pickle.dump(self, file, pickle.HIGHEST_PROTOCOL) my program runs perfectly fine: --------------------------- Testprotocol -----------------------------
0
by: Simon Dahlbacka | last post by:
I'm trying to cache some information using cPickle and I thought that using cPickle.HIGHEST_PROTOCOL would give me an efficient representation. However, when trying to load the information...
2
by: sh | last post by:
Hi guys, Well, I have a (maybe dumb) question. I want to write my own little blog using Python (as a fairly small but doable project for myself to learn more deaply Python in a web context). ...
1
by: A.B., Khalid | last post by:
I wonder if someone can explain what is wrong here. I am pickling a list of dictionaries (see code attached) and unpickling it back using the HIGHEST_PROTOCOL of pickle and cPickle. I am getting an...
2
by: les | last post by:
I am working on a homework assignment and trying to use cPickle to store the answers from questor.py I believe I have the syntax correct but am not sure if I am placing everything where it needs to...
8
by: Jeff Poole | last post by:
This is going to be a pretty vague message because it involves a large block of code I'd rather avoid posting. Basically, I've been pickling a dictionary of instances of a class I've created...
8
by: Victor Kryukov | last post by:
Hello list, I've found the following strange behavior of cPickle. Do you think it's a bug, or is it by design? Best regards, Victor. from pickle import dumps from cPickle import dumps as...
0
by: =?ISO-8859-1?Q?Gerhard_H=E4ring?= | last post by:
gopal mishra wrote: No, there isn't. You could, of course, save each object in its own pickle file. Or use an object database like ZODB instead. -- Gerhard
1
by: Barry | last post by:
I recently tried switching from ElementTree to cElementTree. My application parses a collection of large XML files and creates indexes based on certain attributes. This entire collection is saved...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.