This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: pickle errors
Type: Stage:
Components: Library (Lib) Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: laxori666, tim.peters
Priority: normal Keywords:

Created on 2005-03-06 04:31 by laxori666, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (5)
msg24474 - (view) Author: Laxori666 (laxori666) Date: 2005-03-06 04:31
pickle is giving me an error while I'm trying to
serialize a dictionary.
Here is the dictionary:
>>> a
{' ': (0, 2), '(': (858, 10), ',': (480, 9), '0': (327,
9), '4': (1393, 11), '8': (1396, 11), '@': (3496, 13),
'D': (212, 8), 'H': (1749, 12), 'L': (328, 9), 'P':
(344, 9), 'T': (215, 8), 'X': (4041, 12), '\\': (859,
10), 'd': (16, 5), 'h': (61, 6), 'l': (17, 5), 'p':
(19, 6), 't': (5, 4), 'x': (83, 7), '#': (2632, 12),
"'": (330, 9), '+': (2633, 12), '/': (160, 8), '3':
(697, 10), '7': (2796, 12), '?': (2634, 12), 'C': (175,
8), 'G': (659, 10), 'K': (5571, 13), 'O': (173, 8),
'S': (241, 8), 'W': (662, 10), '[': (144, 9), 'c': (8,
5), 'g': (127, 7), 'k': (161, 8), 'o': (9, 4), 's':
(22, 5), 'w': (104, 7), '\n': (14, 5), '"': (162, 8),
'.': (26, 6), '2': (219, 9), '6': (1399, 11), ':':
(253, 8), 'B': (108, 8), 'F': (426, 9), 'J': (3497,
13), 'N': (146, 9), 'R': (326, 9), 'V': (875, 11), 'Z':
(8080, 13), 'b': (105, 7), 'f': (42, 6), '\xe9': (5570,
13), 'j': (8081, 13), 'n': (27, 5), 'r': (23, 5), 'v':
(37, 7), 'z': (663, 10), '~': (2635, 12), '\t': (2021,
11), '!': (1397, 11), '%': (2784, 12), ')': (1008, 10),
'-': (55, 7), '1': (1009, 10), '5': (4046, 12), '9':
(2797, 12), '=': (15, 5), 'A': (428, 9), 'E': (147, 9),
'I': (481, 9), 'M': (427, 9), 'Q': (436, 10), 'U':
(345, 9), 'Y': (2022, 11), ']': (145, 9), 'a': (29, 5),
'e': (12, 4), 'i': (28, 5), 'm': (62, 6), 'q': (4047,
12), 'u': (12, 5), 'y': (121, 7)}
Here is the series of commands I issue, resulting in an
error:

>>> afile = open("afile", "wb")
>>> p=pickle.Pickler(afile)
>>> p.save(a)
>>> afile.close()
>>> afile = open("afile", "rb")
>>> p=pickle.Unpickler(afile)
>>> a2 = p.load()
Traceback (most recent call last):
  File "<pyshell#69>", line 1, in ?
    a2 = p.load()
  File "H:\Python24\lib\pickle.py", line 872, in load
    dispatch[key](self)
  File "H:\Python24\lib\pickle.py", line 894, in load_eof
    raise EOFError
EOFError

Am I doing something wrong or is this pickle's fault?
msg24475 - (view) Author: Laxori666 (laxori666) Date: 2005-03-06 04:34
Logged In: YES 
user_id=1209371

NOTE: doing this using cPickle works without a problem. Also
note that the file is 2KB smaller under cPickle. If they are
supposed to be using the same stream, I think that is a
problem (the same protocol argument was used for both)
msg24476 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2005-03-06 05:04
Logged In: YES 
user_id=31435

I'm confused by why you're using the Pickler.save() method.  
That's an internal method, not even documented.  If you use 
the documented Pickler.dump() method instead, this should 
work fine with pickle.py.

There's no guarantee about the size or content of pickle 
strings, BTW, and cPickle does play tricks not available to 
pickle.py.
msg24477 - (view) Author: Laxori666 (laxori666) Date: 2005-03-06 05:57
Logged In: YES 
user_id=1209371

Oh, silly me. I should've noticed something was strange when
cPickle didn't have a save method. I don't know, I must've
stumbled into it and thought it was the right one. Thanks
for your help.
msg24478 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2005-03-06 06:41
Logged In: YES 
user_id=31435

No problem -- thanks for the followup!  I'll close this now.

If you ever want to subclass Pickler, then studying the 
source for save() may be helpful.  Otherwise it's best avoided.
History
Date User Action Args
2022-04-11 14:56:10adminsetgithub: 41657
2005-03-06 04:31:11laxori666create