虽然循环显得破碎。与csv阅读器有关

时间:2013-09-18 15:11:33

标签: python file-io while-loop

所以,这非常奇怪。我正在编写一个脚本来接收几个csv文件并比较值。基本上,当我遍历一个文件时,我正在移动一个索引计数器。

这是我用来移动计数器的while循环:

futuresCode = futures[futures_row]['futures_code']
corCode = row[cor_wc_code]    
while(futuresCode < corCode):
                print `futures_row`+' and Futures code: '+`futures[futures_row]['futures_code']`
                futures_row += 1
                futuresCode = futures[futures_row]['futures_code']
                corCode = row[cor_wc_code]

其中futuresCode和corCode是我从CSV文件夹中比较的内部代码。

此代码适用于期货[]中的前13个条目,但是之后它永远不会进入while循环,即使futuresCode保持在99而corCode在到达文件末尾之前继续喜欢194。

在我不知道的循环中是否有一些奇怪的怪癖?

1 个答案:

答案 0 :(得分:4)

Python 2.7.2 (default, Oct 11 2012, 20:14:37)
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> if '194'<'99':
...   print 'gotcha'
...
gotcha

将字符串强制转换为int:

if int('194')<int('99'):