打开已经并关闭存在的文件:
data = open('C:\example', 'r').read() print(data) data_1 = open('C:\小重山','r',encoding = 'utf-8').read() print(data_1)
data.close()
data_1.close()
创建一个文件:
file = open('C:\小重山2','w', encoding = 'utf-8') file.write('hello world!')
file.close()
flush
import sys,time for i in range(30): sys.stdout.write('*') sys.stdout.flush() time.sleep(0.1)