python如何迭代文件中的内容

python迭代文件中的内容的内容的方法:
使用open函数打开文件,用readlines函数获取文件的内容,然后用for循环文件内容就可以了
示例代码如下:
file = open('vv.txt', 'r')
source = file.readlines()
for i in source:
print(i.strip('
'))
执行结果:

更多Python知识,请关注:云海天python教程网!!
来源:PY学习网:原文地址:https://www.py.cn/article.html

