File operations---Based on python

Source: Internet
Author: User

# 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.