python-3.7 - ValueError: int() 以 10 为底的无效文字:'\x00\x00\
问题描述
我有一个列表列表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: int() 以 10 为底的无效文字:'\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
解决方案
推荐阅读
- scikit-learn - 为什么在导出的决策树中只标记父节点的边缘
- c# - 主机关闭连接
- python - 将文本添加到生成的 QListView 窗口
- mysql - 使用 Socket.io 在 HTML 页面上实时查看数据库
- conda - Conda 为离线安装的软件包指定通道
- laravel - Laravel 查询生成器`SELECT (x IN (?)) AS y`
- python - 在 Python 3 中使用变量随机化列表
- javascript - Javascript - 我的函数地理位置权限 onchange 以几何级数返回值
- swift - 如何将一组数据从 Firebase 检索到 iOS 应用程序中
- android - 具有特定页面索引的分页库数据源