Is it possible to pickle python "units" units?

Posted by Ajaxamander on Stack Overflow See other posts from Stack Overflow or by Ajaxamander
Published on 2011-01-03T06:47:37Z Indexed on 2011/01/03 6:53 UTC
Read the original article Hit count: 257

I'm using the Python "units" package (http://pypi.python.org/pypi/units/) and I've run into some trouble when trying to pickle them. I've tried to boil it down to the simplest possible to case to try and figure out what's going on. Here's my simple test:

from units import unit, named_unit
from units.predefined import define_units
from units.compatibility import compatible
from units.registry import REGISTRY

a = unit('m')
a_p = pickle.dumps(a)
a_up = pickle.loads(a_p)

logging.info(repr(unit('m')))
logging.info(repr(a))
logging.info(repr(a_up))

logging.info(a.is_si())
logging.info(a_up.is_si())

logging.info( compatible(a,a_up) )
logging.info(a(10) + a_up(10))

The output I'm seeing when I run this is:

LeafUnit('m', True)
LeafUnit('m', True)
LeafUnit('m', True)
True
True
False
IncompatibleUnitsError

I'd understand if pickling units broke them, if it weren't for the fact that repr() is returning identical results for them. What am I missing?

This is using v0.04 of the units package, and Google App Engine 1.4 SDK 1

© Stack Overflow or respective owner

Related posts about python

Related posts about google-app-engine