ENV:
python: 2.7.5
flask = 0.12.2
flask-cors = 2.0.1
flask-script = 2.0.5
start a python shell:
$ python
Python 2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import math
>>> math.ceil(3.2)
4.0
the math.ceil
return a float, but when I use flask-script
Shell command to start a python shell, it return an integer:
$ ./bin/python manage.py shell
==========================================
Starting server at 2018-01-06 15:30:14
==========================================
In [1]: import math
In [2]: math.ceil(3.2)
Out[2]: 4
I know math.ceil
of python3 will return a integer, but i used python2, anyone has good idea?
check python version:
In [1]: import sys
In [2]: print (sys.version)
2.7.5 (default, Nov 6 2016, 00:28:07)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]
I found the root cause, for our flask app, we add the future package.
future is the missing compatibility layer between Python 2 and Python 3. It allows you to use a single, clean Python 3.x-compatible codebase to support both Python 2 and Python 3 with minimal overhead.
This package rewrite the math.ceil
method, it return an integer:
In [5]: math.ceil.func_code
Out[5]: <code object ceil at 0x7fd74853cab0, file "/data/apps/ecoboost/eggs/future-0.16.0-py2.7.egg/future/backports/misc.py", line 31>
the source code as below:
def ceil(x):
"""
Return the ceiling of x as an int.
This is the smallest integral value >= x.
"""
return int(oldceil(x))