我有这个代码片段,可以对两个文本文件进行一些基本的计算。 我的代码:
with open('one.txt', 'r') as one, open('two.txt', 'r') as two:
next(two) # skip first line in two.txt
for line_one, line_two in zip(one, two):
one_a = int(split(line_one, ",")[0])
two_b = int(split(line_two, " ")[1])
print(one_a - two_b)
我收到以下错误:
Traceback (most recent call last):
File "test.py", line 4, in <module>
one_a = split(line_one, ",")[0]
NameError: name 'split' is not defined
我不知道为什么,非常感谢帮助!
答案 0 :(得分:2)
split
功能无法像这样使用,
你应该使用"some string".split(' ');
所以你的代码应该是
one_a = int((line_one.split(",")[0])
two_b = int(line_two.split(" ")[1])