注册 登录
编程论坛 Python论坛

关于python读取文件的问题

hruyuly 发布于 2018-05-30 20:28, 1130 次点击
程序代码:
with open("C:/Users/Lenovo/Desktop/t.txt","r") as f:
    lines = f.read().split("\n")
cons = [lines[i:i+4] for i in range(0, len(lines)-3), 2]
result = [j for j in cons if 'none' not in j]
print(result)
f.close()

我的程序运行中出现如下的问题,
Traceback (most recent call last):
  File "D:/pycharm/dd/hello.py", line 3, in <module>
    cons = [lines[i:i+4] for i in range(0, len(lines)-3), 2]
TypeError: can only concatenate list (not "int") to list

请问大家可以怎么解决?谢谢。

[此贴子已经被作者于2018-5-31 13:24编辑过]

1 回复
#2
wei_ai_lu2018-05-31 09:29
, 2] 迭代能追加多余元素?有其它效果吗?
1