我有一个列表的列表roots_3 = [['4', '5', '10'], ['11', '12', '13'], ['0', '17', '26'], ['1', '10', '15'], ['4', '19', '26'], ['11', '14', '22'],.... ]
和予想要把所有的价值观里面整数所以我写了一个循环
for i in range(len(roots_3)):
for j in range(len(roots_3[i])):
roots_3[i][j]= np.int(roots_3[i][j])
这是我得到的错误:
ValueError异常:无效的基数为10字面INT():“\ X00 \ X00 \ X00 ...
需要注意的是roots_3从几个文本文件,这样获得的:
for file in files_3:
with open ("/Users/stordd/Desktop/StageI2M/Leiden/k3/{}".format(file), 'r+',encoding="utf8", errors='ignore') as f:
lines = f.readlines()
z = []
for line in lines:
value = line.split()
num_lines = len(f.readlines())
z.append(value[1])
roots_3.append(z)
f.close()
我从运行的C程序的Python脚本的文本文件:
start = time.time()
cmd = ["/Users/stordd/Desktop/StageI2M/C/forestenostre/grezza_foresta", "-w","/Users/stordd/Desktop/StageI2M/Leiden/text_file/USA.txt", "-m", "3", "-e", "-0"]
ntrial = input("How many trials? ")
for i in range(int(ntrial)):
# Open/Create the output file
outFile = open("/Users/stordd/Desktop/StageI2M/Leiden/k3/{}.txt".format(i), 'ab')
result = subprocess.Popen(cmd, stdout=subprocess.PIPE)
out = result.stdout.read()
outFile.write(out)
outFile.close()
time.sleep(1)
end = time.time()
print(end - start)
和文本文件输出也很简单,他们是这样的:
11根
14根
25根