File attributes
File.fileno (): file descriptor file.mode: file opening permission file.encoding: file encoding format file.closed: whether a file is closedCopy the code
Standard file
Stdin: file standard input sys.stdout: file standard output sys.stderr: file standard errorCopy the code
File command line arguments
sys.argv
Copy the code
Encoding format of the file
- U “uses unicode encoding format
- Use the Codecs module to provide methods to create files that specify the encoding format
- Function: codecs. Open (fname, mode, encoding, error, the buffering)
- Mode: enable mode
- Encoding: Indicates the encoding format
The file system
Open the file using the OS module
os.open(filename, flage [, mode])
- Flage is defined as follows
- O_CREAT: creates a file
- O_RDONLY: open in read-only mode
- O_WRONLY: open in write mode only
- O_RDWR: The read/write mode is enabled
- Os. read(fd,buffersize): Reads the file
- Os. write(fd,string): Writes files
- Os.lseek (fd,pos.how): File pointer operation
- Os.close (fd): closes the file