如图:
(上面的输出和这个函数无关)
# 读取文件内容
content = openfile.read()
print(content)
# 按列表读取txt文件内容
content_se = openfile.readlines()
print(content_se)
解决办法
发现把上面代码打上注释代码就能运行了
查询资料发现:
因为在第一个read()之后,光标移到了文件的末尾
后来加入seek(0,0)
# 读取文件内容
content = openfile.read()
print(content)
# 将光标调到文件头
openfile.seek(0, 0)
# 按列表读取txt文件内容
content_se = openfile.readlines()
print(content_se)