Python文件读写

来源:互联网 发布:淘宝小工具 编辑:程序博客网 时间:2024/04/29 10:38

文件写入

file_object = open('myfile.txt', 'w')file_object.write("hello world")file_object.close( )



文件读取

file_object = open('test.txt')try:  str = file_object.read()finally:  file_object.close()print(str)