Python Pickle Problems (Ellipsis + Other Objects)

2011-06-14 Thread Sunjay Varma
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 

    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 : attribute lookup 
__builtin__.ellipsis failed

As well as the data structure which I am pickling:
user_session = {'math_user': {'scope': {'int': , 'DEGREE': 
'DEGREE', 'atan': , 'pow': , 
'fsum': , 'cosh': , 'ldexp': 
, 'hypot': , 'acosh': 
, 'tan': , 'asin': , 'isnan': , 'log': , 'fabs': , 'floor': , 
'atanh': , 'sqrt': , 
'__package__': None, 'frexp': , 'factorial': , 'abs': , 'degrees': , '_': 123, 'fib': , 
'pi': 3.141592653589793, 'log10': , '__doc__': 'This 
module is always available. It provides access to
 mathematical\nfunctions for complex numbers.', 'mode': , 'polar': , 'asinh': , 'float': , 'fmod': , 
'CALC_MODE': 'RADIAN', '__builtins__': {}, 'copysign': , 'cos': , 'ceil': , 
'atan2': , 'isinf': , 'sinh': 
, 'phase': , '__name__': 
'cmath', 'rect': , 'trunc': , 
'expm1': , 'e': 2.718281828459045, 'tanh': , 'radians': , 'sin': , 'lgamma': , 'erf': , 'Vector': , 'erfc': , 
'RADIAN': 'RADIAN', 'modf': , 'Ans': 123, 'exp': , 'acos': , 'log1p': , 'round': , 
'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 "", line 1, in 
    dump(SESSION.data, open("C:\\Session.dump", "wb"), HIGHEST_PROTOCOL)
PicklingError: Can't pickle : attribute lookup 
__builtin__.ellipsis failed
 
Thanks for your help,
Sunjay V. - www.sunjay.ca-- 
http://mail.python.org/mailman/listinfo/python-list


I found some very odd behaviour in Python's very basic types

2011-03-09 Thread Sunjay Varma
For some reason, sub-classing and overwriting a built-in type does not
change the behavior of the literal. Logically speaking, overwriting a
name, such as str, should delete the basic str type, and replace it
with the new class or object put in its place. For some reason though,
even though the interpreter says that str == type("hello"),
overwriting the str name changes nothing in the literal. Is this a
bug? I'm not sure.

I also have just started this very discussion (although in more words)
on Python-Forum.org. Check it out there as well:
http://python-forum.org/pythonforum/viewtopic.php?f=18&t=24542&p=113404

I know a lot of very experienced Python programmers view these mailing
lists. It would be fantastic if this could get fixed. Python would get
momentously more powerful if this feature was implemented. People
would be able to apply new methods and attributes to strings, lists,
dictionaries, sets, and all the built-in types. Improving them when
needed and allowing for extended functionality.

If you prefer to email me directly, just use this email:
haimunt(at)yahoo(dot)com

Thanks for your help! I hope we can discuss this (possible) bug. :)

-Sunjay03
-- 
http://mail.python.org/mailman/listinfo/python-list