rows = []
FILE = open("testing.txt", "r")
for blob in FILE: rows.append([int(i) for i in blob.split(" ")])
这里 testing.txt 包含
01 23 04 05 67
08 09 10
11
12
但是当我运行代码时,我收到以下错误:
ValueError Traceback (most recent call last)
<ipython-input-1-2086c8bf9ab4> in <module>()
1 rows = []
2 FILE = open("testing.txt", "r")
----> 3 for blob in FILE: rows.append([int(i) for i in blob.split(" ")])
ValueError: invalid literal for int() with base 10: ''
所以我的问题是:int() 有什么问题?我认为如果参数是整数(int(5) == 5
例如),那是完全可以的。谢谢你。