Miscellaneous file methods:Close (): close the file to end its access. Releasing a handle as early as possible is a good habit to avoid idle usage of resources. Close file is not displayed, and data in the output buffer may be lost.
Fileno () returns the descriptor of the opened file. The flush () method directly writes data in the internal buffer to the file immediately. The truncate () method truncate the file to the current file pointer location or to the given size, in bytes.
The line separator is different from other file systems: On Posix systems, the line separator is the NEWLINE ('\ n') character, and the old MacOS is the RETURN (\ r) character ), DOS and Wind32 systems use both (\ r \ n ). The path separator Posix uses "/", Dos and Windows uses "\", and the old MacOS uses ":". When the OS module is imported, variables with different cross-platform differences are automatically set to the correct value.
By default, the print statement adds a line break to the end of the output content. You can cancel this operation by adding a comma after the statement. The truncate () method accepts the optional size as the parameter. If given, the file is truncated to a maximum of size bytes. No, the pointer to the current file is truncated. Tell () returns the starting byte position.
Standard file: standard input (generally a keyboard), standard output (buffer output to the display), standard error (non-buffered output to the screen), named the same as c, stdin, stdout, stderr. Access handle: import the sys module and use sys. stdin, sys. stdout, sys. stderr. print statements are usually output to sys. stdout. the built-in raw_input () is usually from sys. stdin accepts input.
The sys. argv attribute provides access to command line parameters. The command line parameter is a parameter other than the program name when calling a program. Sys. argv [0] is always the name of the program
The main interface for OS modular access control system functions. The OS module also handles most file system operations, including deleting/renaming files, traversing directory trees, and managing file access permissions. OS. path can perform operations on path names. It provides functions to manage and operate all parts of the path names of file files, obtain file or subdirectory information, and query file paths.