python file flash close

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/12/13 20:51
# @Author  : flyx
# @Site    : 
# @File    : demo7.py
# @Software: PyCharm
file = open('d.txt','a')
file.write('hello')
file.flush()
file.write('world')
file.close() # 会写入 hello world

# file = open('d.txt','a')
# file.write('hello')
# file.close()
# file.write('world')
# file.close() # 会抛异常

猜你喜欢

转载自blog.csdn.net/qq_34608447/article/details/111145203