Python file processing

Source: Internet
Author: User

1. Create File:

f = File (' myfile.txt ', ' W ') #myfile as file name, W is write permission.

F. Write ("Hello world!") #hello world! is the contents of the file to be written.

F.close () #文件打开后一定要记得关闭 because an error occurs when another program opens the file again.

Permissions for files are also:

w+

r+

A +

WB,RB binary form read and write files

EG1: Real-time Write

Import time

f = File ("F_test.txt", ' W ')

For I in range (15):

Time.sleep (1) #休眠一秒

F.write (' The%s loops\n '% i)

F.flush () #没循环一次 that the data in memory is written to the hard disk.

Time.sleep #循环结束, sleeps 10 seconds

F.close ()

Python file processing

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.