Python 3.0 file Operation basic Process

Source: Internet
Author: User

1, R

data = open (' Monkey King ', ' r ', encoding = ' utf-8 '). Read ()

Print (data)

#该操作为文件的读操作,

2, W

f = open (' Monkey King ', ' w ', encoding = ' utf-8 ')

F.write (' Hello World ')

F.write (' Karen ') #不换行写入两个, not covering ==>hello Worldkaren

#该操作为文件的写操作, overwrite original content re-edit

f = open (' Monkey King 2 ', ' w ', encoding = ' utf-8 ')

F.write (' Hello World ')

#也可创建新的文件进行写操作

3, F = open (' Monkey King ', ' a ', encoding = ' utf-8 ')

F.append (' Hello World ')

#不影响原内容的情况下继续编辑

4, F.readline () #打印第一行的内容 the cursor after the character that is taken

5, F.readlines () #打印多行

6.

Impor Time;time.sleep (#延时缓冲区)

Open () file

F.fileno () file descriptor

F.tell () cursor position when printing

F.seek (0) Move cursor position

F.close () Close file

F.flush () empty buffer, display to terminal

F.truncate truncation, delete the later content

Python 3.0 file Operation basic Process

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.