Python Pickle Problems (Ellipsis + Other Objects)

Sunjay Varma haimunt at yahoo.com
Tue Jun 14 11:23:01 EDT 2011


See more details in my forum post:

http://www.python-forum.org/pythonforum/viewtopic.php?f=18&t=26724


I'm trying to pickle a bunch of functions (mostly built-in) and pickle keeps giving me errors. I have no Ellipsis in my data at all, and for some reason, pickle seems to think I do.

Here is an error I once received:
Traceback (most recent call last):
  File "C:/Sunjay/My Website/projects/sunjay.ca/build/domath", line 132, in <module>
    main()
  File "C:/Sunjay/My Website/projects/sunjay.ca/build/domath", line 127, in main
    actions[action](form)
  File "C:/Sunjay/My Website/projects/sunjay.ca/build/domath", line 107, in do_math
    print SESSION.output()
  File "C:\Python27\lib\site-packages\session.py", line 207, in output
    self.commit()
  File "C:\Python27\lib\site-packages\session.py", line 152, in commit
    dump(data, f, HIGHEST_PROTOCOL)
PicklingError: Can't pickle <type 'ellipsis'>: attribute lookup __builtin__.ellipsis failed

As well as the data structure which I am pickling:
user_session = {'math_user': {'scope': {'int': <type 'int'>, 'DEGREE': 'DEGREE', 'atan': <built-in function atan>, 'pow': <built-in function pow>, 'fsum': <built-in function fsum>, 'cosh': <built-in function cosh>, 'ldexp': <built-in function ldexp>, 'hypot': <built-in function hypot>, 'acosh': <built-in function acosh>, 'tan': <built-in function tan>, 'asin': <built-in function asin>, 'isnan': <built-in function isnan>, 'log': <built-in function log>, 'fabs': <built-in function fabs>, 'floor': <built-in function floor>, 'atanh': <built-in function atanh>, 'sqrt': <built-in function sqrt>, '__package__': None, 'frexp': <built-in function frexp>, 'factorial': <built-in function factorial>, 'abs': <built-in function abs>, 'degrees': <built-in function degrees>, '_': 123, 'fib': <session.FuncData instance at 0x02A6CD50>, 'pi': 3.141592653589793, 'log10': <built-in function log10>, '__doc__': 'This module is always available. It provides access to
 mathematical\nfunctions for complex numbers.', 'mode': <session.FuncData instance at 0x02A6CD78>, 'polar': <built-in function polar>, 'asinh': <built-in function asinh>, 'float': <type 'float'>, 'fmod': <built-in function fmod>, 'CALC_MODE': 'RADIAN', '__builtins__': {}, 'copysign': <built-in function copysign>, 'cos': <built-in function cos>, 'ceil': <built-in function ceil>, 'atan2': <built-in function atan2>, 'isinf': <built-in function isinf>, 'sinh': <built-in function sinh>, 'phase': <built-in function phase>, '__name__': 'cmath', 'rect': <built-in function rect>, 'trunc': <built-in function trunc>, 'expm1': <built-in function expm1>, 'e': 2.718281828459045, 'tanh': <built-in function tanh>, 'radians': <built-in function radians>, 'sin': <built-in function sin>, 'lgamma': <built-in function lgamma>, 'erf': <built-in function erf>, 'Vector': <class 'vector.Vector'>, 'erfc': <built-in function erfc>, 'RADIAN': 'RADIAN', 'modf': <built-in function
 modf>, 'Ans': 123, 'exp': <built-in function exp>, 'acos': <built-in function acos>, 'log1p': <built-in function log1p>, 'round': <built-in function round>, 'gamma': <built-in function gamma>}, 'history': [('123', 123)]}, '__date_loaded__': '2011-06-11'}

The above data structure can be simply put as so:
user_session = {
   "math_user": {
      "scope": {dictionary of all python math functions plus other types and functions},
      "history": [list of previous commands],
      "__date_loaded__": timestamp of today's date
      }
   }

Please help me find out why this code is failing:
>>> from cPickle import dump, HIGHEST_PROTOCOL
>>> dump(user_session, open("C:\\Session.dump", "wb"), HIGHEST_PROTOCOL)
Traceback (most recent call last):
  File "<pyshell#56>", line 1, in <module>
    dump(SESSION.data, open("C:\\Session.dump", "wb"), HIGHEST_PROTOCOL)
PicklingError: Can't pickle <type 'ellipsis'>: attribute lookup __builtin__.ellipsis failed
 
Thanks for your help,
Sunjay V. - www.sunjay.ca
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110614/2a992ba1/attachment.html>


More information about the Python-list mailing list