Detailed descriptions of Python file operation operations instances,

Source: Internet
Author: User

Detailed descriptions of Python file operation operations instances,

This article describes the Python file operation examples. The detailed code is as follows:

#! /Usr/bin/env python #! /Usr/bin/env python # coding: UTF-8 # Purpose: file Operation class # declare a string text poem = ''' Programming is fun test When the work is done if you wanna make your work also fun: use Python! ''' # Create a file class instance in the read-only mode ('R'), write mode ('W'), and append mode ('A ') f=file('poem.txt ', 'A') # open for 'W' riting f. write (poem) # write text to the file write text to file f. close () # close the file # the default is read-only mode f1_file('poem.txt ') # if no mode is specified, 'R' ead mode is assumed by default while True: line = f. readline () # Read every row of the file if len (line) = 0: # Zero length indicates EOF break print line, # output this line # note, because the content read from the file has ended with a line break, we are on the output statement. Use commas to remove line breaks. # Notice comma to avoid automatic newline added by Python f. close () # close the file # help (file)



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.