在python中读取时,将文本的所有值转换为int

在python中读取时,将文本的所有值转换为int,python,numpy,casting,Python,Numpy,Casting,当我试图将值转换为int时,我在python中遇到了这个错误 invalid literal for int() with base 10: '0,72367,72565,73005,73087,73113,73129,73313,73661,74049,74222,74350,74403,74501\n' 我想要的不是这个 0,72367,72565,73005,73087,73113,73129,73313,73661,74049,74222,74350,74403,74501 存储在i

当我试图将值转换为int时,我在python中遇到了这个错误

invalid literal for int() with base 10: '0,72367,72565,73005,73087,73113,73129,73313,73661,74049,74222,74350,74403,74501\n'
我想要的不是这个

0,72367,72565,73005,73087,73113,73129,73313,73661,74049,74222,74350,74403,74501
存储在int的numpy数组中

我的代码是

f = open('points.txt')
# reading the lines of the file
line = f.readline()
while line:
    points = np.array([], dtype=int)
    #print("voxel", voxel_label, " : ", line)
    points = np.append(points, line)
    line = f.readline()
    voxel_label += 1
当我将点转换为int时,它会给我错误。我想从文本文件中读取行,并将其作为int值放入numpy数组点中

points    array(['0,1883,1965,2176,2236,2273,2502,2528,2542,2963,2979,3288,3519\n'],
          dtype='<U62')
点数组(['018831965217622362273250225282542296329732883519\n'],

dtype='如果您的文件纯粹由逗号分隔的数字组成,则需要如下内容:

numbers = []
with open('points.txt', 'r') as f:
    for line in f:
        numbers.extend([int(num)
                       for num in line.split(',')])

# ... do whatever with the numbers list 

请发布产生该错误的代码。该代码在注释中不可读。请编辑您的问题以添加您尝试的代码。您可以编辑您的问题并将其放入其中吗?在注释中阅读确实很困难。python函数
int
接受一个数字的字符串,而不是一组数字。请在注释中阅读其文档内容代码示例将产生您所询问的错误。欢迎使用SO。请花时间阅读。以及在该页面上找到的其他链接。当我尝试此操作时,它给出了“\io.TextIOWrapper”对象没有属性“split”此错误Whoops刚刚发现错误!
f
需要
line
。我将进行编辑