python-Error Message: 'float' object cannot be interpreted as an integer
来源:互联网 发布:复合材料的刚度矩阵 编辑:程序博客网 时间:2024/06/05 18:19
背景
因为需要通过模拟回调,所以自己写了一段脚本来获取数据库内的数据,然后通知给应用。代码在py2运行得好好的,结果copy在py3上面就报错。
出问题的代码如下:
batch = 200for x in range(len(order_nos) / batch + 1): # do something
order_nos 是订单列表。脚本主要的功能是分批次回调,一个批次200. 报错信息的意思是:float类型不能解释为int类型 。 奇怪得很,py2都好好的,到py3就不行 。
问题解决
为什么range内的数据是float呢 ?
怀疑/
在py2跟py3之间有差别,搜了一下,的确是有差别。请看下面的用法:
pyhon2
C:\Users\chenjun>python
Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (
AMD64)] on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> 0/200 + 1
1
>>> 1/200 + 1
1
python3
C:\Users\chenjun>python3
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 17:54:52) [MSC v.1900 32 bit (Intel)]
on win32
Type “help”, “copyright”, “credits” or “license” for more information.
>>> 0/200 + 1
1.0
>>> 1/200 + 1
1.005
在python2,/
只留下了整数部分,去掉了小数,是int型。而在python3里,/
的结果是真正意义上的除法,结果是float型。所以便出现了Error Message: ‘float’ object cannot be interpreted as an integer。
- python-Error Message: 'float' object cannot be interpreted as an integer
- python3中Error Message: ‘float’ object cannot be interpreted as an integer
- TypeError: 'float' object cannot be interpreted as an integer
- TypeError: 'numpy.float64' object cannot be interpreted as an integer
- TypeError numpy.float64 object cannot be interpreted as an index
- TypeError: 'numpy.float64' object cannot be interpreted as an index
- TypeError: 'numpy.float64' object cannot be interpreted as an index
- TypeError numpy.float64 object cannot be interpreted as an index
- TypeError: 'numpy.float64' object cannot be interpreted as an index
- TypeError numpy.float64 object cannot be interpreted as an index解决
- Windows下TypeError numpy.float64 object cannot be interpreted as an index的解决
- python write出现 Non-character array cannot be interpreted as character buffer.
- “An error message cannot be displayed because an optional resource assembly containing it cannot be found“ 怎么解决
- 调试CRF出现的错误:cannot be interpreted as a Tensor.
- Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
- PLS-00363: expression 'v_s' cannot be used as an assignment target
- Fatal error: Cannot use 'Object' as class name as it is reserved in xxx/Object.php on line 77
- Android Studio 3 Error Message:The activity must be exported or contain an intent-filter
- 任学堂---人工智能真的来了,这些职业会消失!生活也会发生翻天覆地的变化
- The Two Routes CodeForces
- jquery validate单独校验某一字段
- Python 安装(pip)
- Java 实现HTTP协议
- python-Error Message: 'float' object cannot be interpreted as an integer
- SpringBoot学习-简单QuartZ定时器设置
- 键盘的 meta 按键
- 《android日常bug系列》使用dagger2,找不到DaggerActivityComponent
- 支持向量机通俗导论(理解SVM的三层境界)
- Java NIO中Buffer常用方法的用法及理解
- java获取一个目录下的所有的文件或文件夹名称
- JAVA学习笔记12——Structs2框架第二章
- 欢迎使用CSDN-markdown编辑器