1.打开文件:
f = open("xx.txt","r+") //the "r+" can allow you to read and write the file , "r" can only allow you to read it
2.写入文件:
my_file.write(anything you want but in String formation) // it can only be used when you are allowed to write
3.读文件:
my_file.read() // the returned value will be the content of the text
4.关闭文件:
my_file.close()
5.可以查看closed属性判断文件是否关闭,如果为True,则表示文件已经关闭,如果为False则表示文件未关闭。
本文介绍了如何使用Python进行基本的文件操作,包括打开、读取、写入及关闭文件等步骤,并提供了示例代码来帮助理解。

被折叠的 条评论
为什么被折叠?



