环境:
python: 2.7.5
flask = 0.12.2
flask-cors = 2.0.1
flask-script = 2.0.5
启动python shell:
^{pr2}$math.ceil
返回一个float,但是当我使用flask-script
Shell命令启动python Shell时,它返回一个整数:
$ ./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
我知道python3的math.ceil
将返回一个整数,但我使用python2,有谁有好主意?在
检查python版本:
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)]
我找到了根本原因,对于我们的flask应用程序,我们添加了future包。在
此包重写
math.ceil
方法,它返回一个整数:源代码如下:
^{pr2}$虽然看起来4是个整数。flask脚本有可能在没有十进制展开的情况下打印它。试着跑步
写在烧瓶上。如果工作正常,它将打印
1.3333333333333333
。如果它打印1
,那么您应该尝试重新安装flask脚本。在相关问题 更多 >
编程相关推荐