OS. sep can replace OS. linesep, which is the path delimiter specified by the operating system.
The OS. linesep string specifies the row Terminator used by the current platform. For example, in Windows, '\ r \ n' is used, in Linux,' \ n' is used, and in Mac, '\ r' is used '.
The OS. name string indicates the platform you are using. For example, for Windows, it is 'nt ', and for Linux/Unix users, it is 'posix'
OS. getcwd () function to get the current working directory,
The OS. getenv () and OS. putenv () functions are used to read and set environment variables respectively.
OS. listdir (dirname): list directories and files under dirname
The OS. remove () function is used to delete an object.
OS. curdir: returned but the former Directory ('.')
OS. chdir (dirname): change the working directory to dirname
Getatime (path): The Last access time of a file or folder, from the New Age to the access time in seconds
Getmtime (path): The last modification time of a file or folder.
Getctime (path): the time when a file or folder is created.
OS. path module:
The OS. path. isfile () and OS. path. isdir () functions verify whether the given path is a file or a directory, and return the bool value.
The OS. path. exists () function is used to check whether the given path actually exists and returns bool.
OS. path. getsize (name): get the file size. if name is a directory, return 0L. return long in bytes.
OS. path. abspath (name): obtain the absolute path.
OS. path. normpath (path): specifies the path string format. The result is usually///,
OS. path. split (name): divide the name into a path name and a file name. The result is (path name, file name. file extension) (in fact, if you fully use a directory, it will also separate the last Directory as a file name, and it will not determine whether the file or directory exists)
OS. path. splitext (filename): the results of splitting the file name and extension are (filename, extension). If the parameter is a path, return (path ,'')
OS. path. join (path, name): The connection directory and file name or directory result is path/name
OS. path. basename (path): The Returned file name is actually the last "/" of the path, and the latter is returned. Whether the parameter is a path or the file is the same as OS. path. split (name), the latter returns two worthy tuples.
OS. path. dirname (path): The Return file path actually splits the last "/" of the path and returns the former. Whether the parameter is a path or a file
The OS. system () function is used to run shell commands.
The above is only common and lists all of the following:
The OS module encapsulates common interfaces of different operating systems, so that users can use the same function interface in different operating systems to return results of the same structure.
OS. name: returns the name of the current operating system ('posix', 'nt ', 'oss2', 'mac', 'Ce' or 'riscos ')
OS defines a set of file and path representation parameters in different operating systems, such
OS. sep (folder separator, which is \ in windows \)
OS. extsep (extension separator, which is. in windows .)
OS. pathsep (directory separator, which is in windows ;)
OS. linesep (line break separator, \ r \ n in windows)
OS has a large number of file and path operations related functions, such:
Listdir (path): lists all objects in the directory.
Makedir (path): create a folder. note: An exception occurs when an existing folder is created.
Makedirs (path): recursively creates a folder. note: Creating an existing folder will cause an exception.
Remove (filename): delete an object
Rmdir (path): Delete a folder. note: deleting a non-empty folder will cause an exception.
Removedirs (path): recursively deletes a folder until a level-1 folder is not empty. note: the folder path cannot end '\'.
Rename (src, dst): rename a file or folder (you can change the path but cannot overwrite the target file)
Renames (src, dst): recursively renames a file or file name.
Walk (path): lists all files and folders in the path.
Process-related operations in OS, such:
Execl (path): runs a program to replace the current process, and runs in blocking mode.
_ Exit (n): exit the program
Startfile (filename): run the program associated with the file. after the associated program is opened, return immediately.
System (cmd): If you run a program or command, the system returns immediately. after the command is executed in cmd, the system returns the cmd exit code.
OS. path: calls different modules in different operating systems. it is an import module that provides many useful operations:
Abspath (path): returns the absolute path of the path. if the path is already an absolute path, it is maintained.
Basename (path): returns the file name in path.
Commonprefix (list): returns the unified prefix in the list to obtain the same content from the left of a string.
Dirname (path): returns the folder section in the path. The result does not contain '\'
Exists (path): whether a file or folder exists
Getatime (path): The Last access time of a file or folder, from the New Age to the access time in seconds
Getmtime (path): The last modification time of a file or folder.
Getctime (path): the time when a file or folder is created.
Getsize (path): the size of a file or folder. if it is a folder, 0 is returned.
Isabs (path): returns whether it is an absolute path.
Isfile (path): whether to return the file path
Isdir (path): returns whether it is a folder path.
Islink (path): whether to return a shortcut
Join (path1, path2,...): combines paths. if there is an absolute path, the previous path will be deleted.
Normcase (path): The delimiter in the conversion path
Normpath (path): The conversion path is a recognizable path.
Realpath (path): The conversion path is an absolute path.
Split (path): splits the path into (folder, file name)
Splitext (path): splits the path into (other parts,. extension). If the file name does not contain an extension, the extension is a null string.
An OSError exception is thrown when an object is not supported by the operating system.