Python-文件

写文件

with open('test.txt','w') as file_object:
    file_object.write('Hello Python!')

追加文件

with open('test.txt','a') as file_object:
    file_object.write('Hello Python again!')

读文件

with open('test.txt') as file_object:
    content = file_object.read()
    print(content)

输出

Hello Python!Hello Python again!

猜你喜欢

转载自blog.csdn.net/yirentianran/article/details/80065666
今日推荐