ArticleDirectory
- OS module attributes
- File object Method
- OS module File/directory access function
- Path Name access function in the OS. Path Module
OS module attributes
Attribute name |
Description |
Linesep |
String used to split rows in a file |
SEP |
String used to separate the file path name |
Pathseq |
String used to separate file paths |
Curdir |
String name of the current working directory |
Pardir |
(Current working directory) parent directory string name |
File object Method
Attribute name |
Description |
File. Close () |
Close file |
File. fileno () |
Returns the file descriptor. |
File. Flush () |
Refresh the file's internal swap Zone |
File. isatty () |
Determines whether the file is a tty-like device. |
File. Next () |
Returns the next line of the file (similar to file. Readline (), or triggers a stopiteration exception when no other rows exist. |
File. Read (size =-1) |
Read size bytes from the file. When no size is specified or negative value is given, read all remaining bytes and return them as strings. |
File. Readline (size =-1) |
Read from the file and return a row (including the row Terminator) |
File. readlines (sizhint = 0) |
Reads all rows of the file and returns the result as a list (including all row Terminators ). If the given sizhint is greater than 0, the total number of rows in the sizhint bytes is returned (the size is determined by the next value of the buffer capacity) |
File. Seek (Off, whence = 0) |
Move the file pointer in the file, and offset off byte from whence (0 indicates the start of the file, 1 indicates the current position, and 2 indicates the end of the file) |
File. Tell () |
Returns the current position in the file. |
File. truncate (size = fill. Tell ()) |
Returns the maximum size of the file. The default value is the current file location. |
File. Write (STR) |
Write a string to a file |
File. writelines (SEQ) |
Writing string sequence seq to a file |
OS module File/directory access function
Method |
Description |
File Processing |
Mkfifo ()/mknod () |
Create named pipelines/create files/file system nodes |
Remove ()/unlink () |
Delete an object |
Rename () |
Rename a file |
Stat () |
Returned File Information |
Symlink () |
Create a symbolic link |
Utime () |
Update Time cut |
Tmpfile () |
Create and open a new temporary file |
Walk () |
Generate all file names under a directory tree |
Directory/folder |
Chdir () |
Change current working directory |
Chroot () |
Change the root directory of the current process |
Listdir () |
List objects in a specified directory |
Getcwd () |
Back to current working directory |
Mkdir |
Create (multi-tier) Directories |
Rmdir |
Delete (multi-tier) Directories |
Access/permission |
Access () |
Verify permission Mode |
Chmod () |
Change permission Mode |
Chown () |
Change owner and group ID |
Umask () |
Set the default permission Mode |
File descriptor operations |
Open () |
Underlying operating system open |
Read/write () |
Seek/Write Data Based on file descriptors |
DUP ()/dup2 () |
Copy file descriptor/function is the same, but will be copied to another file descriptor |
Path Name access function in the OS. Path Module
Method |
Description |
Separate |
Basename () |
Remove the directory path and return the file name. |
Dirname () |
Remove the file name and return the directory path. |
Join () |
Combine the separated parts into a path name |
Split () |
Returns the (dirname (), basename () tuples. |
Splitdrive () |
Returns the (drivename, pathname) tuples. |
Information |
Getatime () |
Returns the last access time. |
Getctime () |
Returns the file creation time. |
Getmtime () |
Returns the last file modification time. |
Getsize () |
Size of the returned file (in bytes) |
Query |
Exists () |
Whether the specified file or directory exists |
Isabs () |
Absolute path? |
Isdir () |
Is it a directory? |
Isfile () |
Is it a file? |
Islink () |
Symbolic Link or not |
Ismount () |
Whether it is a mount point |
Samefile () |
Whether the two pathnames point to the same file |
Delete a directory continuously. For example, a folder contains a directory B, c folder, and C folder contains test.txt.
Import shutilshutil. rmtree (r 'd: \ ')