Python 里的I/O文件操作

来源:互联网 发布:涵曦瘦身霜有害知乎 编辑:程序博客网 时间:2024/05/18 14:25

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则表示文件未关闭。


0 0
原创粉丝点击