type object 'Decimal' has no attribute 'from_float'

This is the place for queries that don't fit in any of the other categories.

type object 'Decimal' has no attribute 'from_float'

Postby Preethi » Sat May 10, 2014 11:44 am

Hi,

I am new to python. I am getting an error "AttributeError: type object 'Decimal' has no attribute 'from_float'" when I run the following in python prompt:

Code: Select all
>>> from future.builtins import int, round
>>> int(round(5))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/future/builtins/backports/newround.py", line 32, in newround
    d = Decimal.from_float(number).quantize(exponent,
AttributeError: type object 'Decimal' has no attribute 'from_float'


I am running this on Centos 6.5 which has python version 2.6.6
This is the output of 'pip freeze':

Code: Select all
Django==1.6.4
Mezzanine==3.1.4
Pillow==2.4.0
South==0.8.4
bleach==1.4
django-appconf==0.6
django-compressor==1.3
filebrowser-safe==0.3.3
future==0.9.0
grappelli-safe==0.3.10
html5lib==0.999
iniparse==0.3.1
oauthlib==0.6.1
psycopg2==2.5.2
pycurl==7.19.0
pygpgme==0.1
pytz==2014.2
requests==2.2.1
requests-oauthlib==0.4.0
six==1.6.1
tzlocal==1.0
urlgrabber==3.9.1
yum-metadata-parser==1.1.2


This is the order in which I installed the above packages. (The box initially had python 2.6.6 installed)

yum install gcc python python-setuptools python-devel
yum install libjpeg-turbo-devel
python get-pip.py
pip install -U pip
pip install South django-compressor
pip install mezzanine
yum install postgresql93-server.x86_64
yum install postgresql-devel
sudo pip install psycopg2

What am I missing? Any help is greatly appreciated.

Thanks,
Preethi
Last edited by Yoriz on Sat May 10, 2014 12:04 pm, edited 2 times in total.
Reason: First post lock, Added code tags, Changed Title.
Preethi
 
Posts: 2
Joined: Sat May 10, 2014 11:41 am

Re: Error while calling round() from future.builtins

Postby Yoriz » Sat May 10, 2014 12:02 pm

Hi welcome to the forum.
Please read the new users read this link in my signature.

The method from_float was added to Decimal in python version 2.7
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!
Spam topic disapproval technician
Windows7, Python 2.7.4., WxPython 2.9.5.0., some Python 3.3
User avatar
Yoriz
 
Posts: 837
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

Re: type object 'Decimal' has no attribute 'from_float'

Postby 7stud » Sun May 11, 2014 4:19 am

1) int() and round() were available in python 2.6, and as far as I can tell the result each produces hasn't changed since then, so why are you doing a future import?

2) if you want to remain with python 2.x, you should install python 2.7, It doesn't really make sense to use an up to date django version with an old python version.
7stud
 
Posts: 106
Joined: Wed Apr 02, 2014 2:36 am

Re: type object 'Decimal' has no attribute 'from_float'

Postby Preethi » Mon May 12, 2014 12:03 pm

Thanks. I upgraded the future library to 0.12.0 and it works. I will upgrade to python 2.7
Preethi
 
Posts: 2
Joined: Sat May 10, 2014 11:41 am

Re: type object 'Decimal' has no attribute 'from_float'

Postby 7stud » Mon May 12, 2014 6:48 pm

Why do you need to use future for int() and round()?
7stud
 
Posts: 106
Joined: Wed Apr 02, 2014 2:36 am


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], W3C [Linkcheck] and 6 guests