我需要将两个文件中的数据相互减去,但我得到了这个error:NameError:未定义名称“first1”。你能告诉我怎么纠正这个错误吗?我用来运行代码的命令如下:python script.py input1.txt input2.txt>;输出.txt
import numpy
from numpy import *
import scipy
from pylab import *
import sys
def main(argv):
t = open(sys.argv[1])
first1 = t.readline()
tt = open(argv[2])
second2 = tt.readline()
return [first1], [second2]
def result(first1, second2):
first = np.array(first1, dtype = np.float64)
second = np.array(second2, dtype = np.float64)
#subtract
sub = (first - second)
return [sub]
result(first1, second2)
if __name__ == '__main__':
sys.exit(main(sys.argv))
input1.txt:
2.5
2.8
3.9
4.2
5.8
input2.txt:
0.8
2.5
3.2
5.8
6.3
我不知道你到底想做什么,但是你的代码中有很多错误。以下是一个工作版本:
相关问题 更多 >
编程相关推荐