竹磬网-邵珠庆の日记 生命只有一次,你可以用它来做些更多伟大的事情–Make the world a little better and easier


127月/1115

Python:读写文件

发布在 邵珠庆

1.open

使用open打开文件后一定要记得调用文件对象的close()方法。比如可以用try/finally语句来确保最后能关闭文件

file_object = open('thefile.txt')
try
:
     all_the_text
=
file_object.read( )
finally
:
     file_objec

[......]阅读全文