作者:ym_泳梅 | 来源:互联网 | 2022-09-26 03:27
python读取文本文件的方法:首先使用open()方法打开一个文本文件;然后使用f.read()方法读取此文件;最后使用f.close()方法关闭文件即可。
python怎么读取文本文件?
文件的读取
步骤:打开 -- 读取 -- 关闭
>>> f = open('/tmp/test.txt')
>>> f.read()
'hello python!\nhello world!\n'
>>> f.close()