文件操作

打开已经并关闭存在的文件:

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)

 

posted @ 2018-06-22 15:04  evatan123  阅读(69)  评论(0编辑  收藏  举报