kdavies4 / natu

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

failed: NameError: name 'reduce' is not defined #28

Closed MinhHaDuong closed 7 years ago

MinhHaDuong commented 8 years ago

``Python 3.4.3+ (default, Oct 14 2015, 16:03:50) [GCC 5.2.1 20151010] on linux Type "help", "copyright", "credits" or "license" for more information.

from natu.units import m l = 1m l Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.4/dist-packages/natu/core.py", line 823, in repr return format(self, 'g') File "/usr/local/lib/python3.4/dist-packages/natu/core.py", line 357, in wrapped unit = unitspace(display_unit) File "/usr/local/lib/python3.4/dist-packages/natu/core.py", line 1374, in call return reduce(lambda x, y: x \ y, factors) NameError: name 'reduce' is not defined ``

MinhHaDuong commented 8 years ago

Proposed fix:

Use a for loop instead of reduce in core.py as follows:

< # Avoid using reduce to be portable between Python v2 and v3
< #            return reduce(lambda x, y: x * y, factors)
<             result = factors[0]
<             for x in factors[1:]:
<                 result = result * x
<             return result
< #
---
>             return reduce(lambda x, y: x * y, factors)

And delete line 47 in util.py

MinhHaDuong commented 7 years ago

Closing, there is a from functools import wraps, reduce in core.py