473,385 Members | 1,324 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,385 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 1299
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.