我编写了一个小python脚本,以便从我在shell上编写的csv文件中提取数字。
from csv import reader
def ext(fileName):
l= []
with open(fileName, delimiter = '\n' ) as inp:
for row in inp:
l += [row]
print(l)用我的测试文件,我得到:
['1\n', '2\n', '5\n', '3\n', '6\n']我怎样才能清楚地表明我是在提取数字而不是字符串?(我想把这些数字存储在一个列表中)
发布于 2013-10-31 08:43:19
不要使用l += [row],而是使用l.append(int(row))。这应该能行
https://stackoverflow.com/questions/19701781
复制相似问题