我有一个文本文件“luawrite”,其中我将每一行分成 4 列,并将(第 3 列值乘以 8)除以第 4 列值。文件 luawrite 如下所示:
0.012281001 00:1c:c4:c2:1f:fe 1441 44000000
0.012285001 00:1c:c4:c2:1f:fe 1441 44000000
0.012288001 00:1c:c4:c2:1f:fe 1441 44000000
0.012292001 00:1c:c4:c2:1f:fe 1441 44000000
0.012295001 00:1c:c4:c2:1f:fe 1441 44000000
0.012299001 00:1c:c4:c2:1f:fe 1441 44000000
0.012302001 00:1c:c4:c2:1f:fe 1441 44000000
我为此编写的代码如下:
#!/usr/bin/python
import collections
result = collections.defaultdict(int)
with open("luawrite", "r") as f:
for line in f:
hashes = line.split()
val1 = int(hashes[2])
val2 = int(hashes[3])
k = (val1*8)/val2
print k
我正在使用python 2.6。但我得到的解决方案都是零。这段代码的问题在哪里,请告诉我。这可能是一个小错误,但我无法找到它。谢谢!