Python编程从入门到实践~文件读取
生活随笔
收集整理的這篇文章主要介紹了
Python编程从入门到实践~文件读取
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
#讀取整個文件
filename = './data/read.log'
with open(filename, 'r', encoding='utf-8') as file_object:contents = file_object.read()print(contents)#逐行讀取
filename = './data/read.log'
with open(filename, 'r', encoding='utf-8') as file_object:for line in file_object:print(line)#讀取文件內(nèi)容為列表
filename = './data/read.log'
with open(filename, 'r', encoding='utf-8') as file_object:lines = file_object.readlines()for line in lines:print(line.rstrip())
總結(jié)
以上是生活随笔為你收集整理的Python编程从入门到实践~文件读取的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 简评黑客利器——中国菜刀
- 下一篇: Template Method 和 St