Python file operation class operation examples in detail
Update: July 11, 2014 10:59:47 contribute sth.:shichen2014
This article introduces the Python file operation class operation example code, need friends can refer to the following
This article describes the operation of the Python file manipulation class example, the detailed code is as follows:
#!/usr/bin/env python #!/usr/bin/env python #coding:utf-8 # Purpose: File manipulation class # Declare a string text poem=''' Programming is funbeta (software) When the work is done if you wanna make your work also fun: use Python! ''' # Create an instance of the file class, the mode can be: read-only ('r'), write ('w'), append ('a') f=file('','a') #open for 'w'riting (poem) # write text to file write text to file () #Close file close the file # Default is read-only mode f=file('') # if no mode is specified,'r'ead mode is assumed by default while True: line=() # Read every line of the file if len(line)==0: # Zero length indicates EOF break print line, # Output the line # Note that since the read from the file already ends with a newline, we use commas on the output statements to eliminate the automatic newlines. #Notice comma to avoid automatic newline added by Python () #close the file #Help help(file)
Related articles
Python implementation of the projection method of image segmentation example (I)
Today I'd like to share a Python implementation of the projection method of image segmentation example, with good reference value, I hope to help you. Together follow the editor over to see it2020-01-01Python import and from import usage and differences explained
Python program can call a set of basic functions (i.e. built-in functions), such as print(), input() and len() functions. Next, through this article to give you an introduction to Python import and from import use and difference between the introduction, interested friends take a look together!2021-09-09Drawing diagrams in Python (magic function based on Jupyter notebook)
This article introduces the drawing in Python (based on the magic function of Jupyter notebook), the text through the sample code is very detailed, for everyone's learning or work has a certain reference to the learning value, the need for friends can refer to the following2019-10-10python implementation of tencent slider captcha recognition
This article mainly introduces python how to realize tencent slider verification code recognition, to help you better understand and learn to use python, interested friends can understand the2021-04-04python uses the requests module to send http requests.
This article introduces a step-by-step python using requests module to send http requests method, very good, with a certain reference value, the need for friends can refer to the following2018-12-12Python syntax of the subtle ten knowledge points (pretend B syntax)
This article carefully screened the most to show the subtlety of Python syntax of the ten knowledge points, and attached detailed example code, if you need friends can refer to the following2020-01-01(usage
This article introduces the () usage description, with good reference value, I hope to help you. Together follow the editor over to see it2020-06-06Python Implementation of Critical Path and Heptagram Calculations Explained
This article is mainly for you to introduce in detail how to use Python to achieve the critical path and the calculation of the seven-grid map, the sample code in the text explains the details, interested partners can follow the editor together to understand a little2023-03-03Python Multi-Threading Examples
This article introduces the Python multi-threaded example of the relevant information, the need for friends can refer to the following2017-03-03Python reflective manipulation of object attributes method details
This article introduces the Python reflection operation object properties method explained, in the face of the object in Python, through the form of a string to operate the object's attribute method is called reflection (in Python, all things can be for the object), the need for friends can refer to the following2023-08-08