我有这个代码片段,可以对两个文本文件进行一些基本计算。 我的代码:
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
我不知道为什么,非常感谢您的帮助!
最佳答案
split
函数不能这样使用,
你应该使用 "some string".split(' ');
所以你的代码应该是
one_a = int((line_one.split(",")[0])
two_b = int(line_two.split(" ")[1])
关于python-3.x - 名称 'split' 未定义问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48803260/