# Coding:utf-8
From time import sleep
Import Sys
Reload (SYS)
Sys.setdefaultencoding ("UTF8")
F=open (R "E:\test\window.txt", "R") #以读的方式打开
Fp=f.read () #把读取出来的内容放到缓存
Print FP
F.close () #关闭文件清除缓存
Sleep (1)
F=open (R "E:\test\window.txt", "W") #以写的方式打开, will be emptied before writing
F.write ("aaaa\nbbbbbb\nccccc\tddddd\n me who is the package file put to the hair of the room rate") #把读取出来的内容放到缓存
F.close () #关闭文件回收内存
Sleep (1)
F=open (R "E:\test\window.txt", "R") #以读的方式打开
Fp=f.read () #把读取出来的内容放到缓存
Print FP
F.close () #关闭文件清除缓存
F=open (R "E:\test\window.txt", "a") #a表示追加写入
F.write ("aaaa\nbbbbbb\nccccc\tddddd\n me who is the package file put to the hair of the room rate") #把读取出来的内容放到缓存
F.close () #关闭文件回收内存
Sleep (1)
#下面是以二进制的方式写入
F=open (R "E:\test\window.txt", "WB") #wb # indicates a binary write
F.write ("aaaa\nbbbbbb\nccccc\tddddd\n me who is the package file put to the hair of the room rate") #把读取出来的内容放到缓存
F.close () #关闭文件回收内存
Sleep (1)
F=open (R "E:\test\window.txt", "R") #以读的方式打开
Fp=f.read () #把读取出来的内容放到缓存
Print FP
F.close () #关闭文件清除缓存
Another way: (with open ... as, this method does not have close)
With open (r "E:\test\window.txt", "a") as F:
F.write ("mamamiya\ndafdfa\tad\n6666")
With open (r "E:\test\window.txt", "R") as F:
Fp=f.read ()
Print FP
File operations---Based on python