我有一个列表列表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)
和文本文件的输出非常简单,它们看起来像这样:
radice 11
弧度14
弧度25