On 08/06/13 15:18, Stephen J. Turnbull wrote:
Ethan Furman writes:

  > Enumerations can be pickled and unpickled::
  >
  >      >>> from enum import Enum
  >      >>> class Fruit(Enum):
  >      ...     tomato = 1
  >      ...     banana = 2
  >      ...     cherry = 3
  >      ...
  >      >>> from pickle import dumps, loads
  >      >>> Fruit.tomato is loads(dumps(Fruit.tomato))
  >      True
  > [...]
  > Still, it would be nice if this could work.

Well, you could cheat and reverse the test. ;-)

I assume the problem is that loads proceeds to recreate the Fruit
enum, rather than checking if there already is one?


I don't believe so. I understand that the problem is that pickle cannot find 
the Fruit enum in the __main__ module.

Untested, but adding this before the call to dumps might work:

import __main__
__main__.Fruit = Fruit


although that's the sort of thing that makes me think it's time to turn this 
into a unittest rather than a doctest.



--
Steven
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to