kdavies4 / natu

Natural units in Python
http://kdavies4.github.io/natu/
Other
33 stars 5 forks source link

fixed missing commit in core.py #21

Closed anoetos closed 9 years ago

anoetos commented 9 years ago

@kdavies4 hello, missing import of reduce caused following crash in python3

>>> from natu.units import K
>>> 1.*K
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.4/site-packages/natu/core.py", line 823, in __repr__
    return format(self, 'g')
  File "/usr/lib/python3.4/site-packages/natu/core.py", line 357, in wrapped
    unit = unitspace(**display_unit)
  File "/usr/lib/python3.4/site-packages/natu/core.py", line 1374, in __call__
    return reduce(lambda x, y: x * y, factors)
NameError: name 'reduce' is not defined
>>> 

added import of reduce in core.py source file to make it work:

>>> from natu.units import K
>>> 1.*K
1 K
>>> 

i would also like to take the opportunity to say "thank you" for sharing this wonderful library =)

anoetos commented 9 years ago

also getattr ran into infinite recursion in python3, breaking copy.deepcopy, you can try by running

from natu.units import K
import copy
v = 1.*K
w = copy.deepcopy(v)
print(w)

so i added a check for existence of '_value'-attribute used to delegate the unknown attribute requests to.

kdavies4 commented 9 years ago

@anoetos, thanks for your encouragement and for the fixes. I'm on vacation and may not get back to this for a while, so I'll just go ahead and approve the pull request.