I. file systems and documentation
1. File systems and files
A file system is the method and data structure used by the OS to clear files on a disk or partition-the method of organizing files on disk
computer files (or files, computer archives, files) are a stream of data stored in a long-term storage device or temporary storage device, and belong to the computer file system Management
Generally speaking:
A file is a name-controlled storage area of the computer that is managed by the OS
On a Linux system, a file is considered a sequence of bytes
2. Architecture of Linux File system components
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/87/4F/wKioL1fcuJzgMDmgAAEBsoQn_y4470.png "title=" 5%qnu] 1qv1w~r7]g2{o{mm0.png "alt=" Wkiol1fcujzgmdmgaaebsoqn_y4470.png "/>
3. Python Open File
Python built-in function open () for opening files and creating file objects
Syntax format:
open (Name[,mode[,bufsize]])
The Open method can receive three parameters: file name, pattern, and buffer parameters
The open function returns a file object
Mode: Specifies the open mode of the file
BufSize: Defining output caching
0 indicates no output cache
1 indicates the use of buffering
Negative numbers mean using system default settings
A positive number indicates a buffer with an approximate specified size
4. Open mode of File
Simple mode:
R: Read-only
Open ('/var/log/message.log ', ' R ')
W: Write
A: Additional
Use "+" after pattern to support input and output operations at the same time
such as r+, w+ and A +
Append "B" to the pattern to open in binary mode
such as RB, wb+
5. File method
650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/87/4F/wKioL1fcuZ3TD7fCAAI8vu9Z7x8038.png "title=" fc3~ zmh_}%3$3) ag8k1q%_6.png "alt=" Wkiol1fcuz3td7fcaai8vu9z7x8038.png "/>
The file object maintains the state of the file it opens, and its tell () method returns the current position in the open file
The read () method is used to read a file into a single string, or it can specify the number of bytes to read
ReadLine () can read the next line to a string, including the Terminator of the end of the line
ReadLines () reads all lines of the entire file into a list of strings in the behavior unit
Write (astring) output byte string to file
Writelines (alist) is used to write all the strings in the list to the file
File operation:
Attention
The file method read () reads the file with its line terminator
File method Write () does not automatically add a line terminator to the write operation
When implementing a file read or write in a Python program, convert the object to a string using the conversion tool
Pickle Module
Shelve module
6. File Object Properties
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/87/51/wKiom1fcukrT4COtAACwzuToiHo688.png "title=" 30C} n9ro@j6m}@1p) td1[q3.png "alt=" Wkiom1fcukrt4cotaacwzutoiho688.png "/>
This article is from the "Xiexiaojun" blog, make sure to keep this source http://xiexiaojun.blog.51cto.com/2305291/1853398
Python v. Python file object