Python note-1, python note

Source: Internet
Author: User

Python note-1, python note

OS module Description: the python OS module contains common operating system functions.

OS. access (path, mode) # verify the permission mode
OS. chdir (path) # change the current working directory
OS. chflags (path, flags) # set the path tag as a number tag.
OS. chmod (path, mode) # Change permissions
OS. chown (path, uid, gid) # change the file owner
OS. chroot (path) # change the root directory of the current process
OS. close (fd) # disable file descriptor fd
OS. closerange (fd_low, fd_high) # Close all file descriptors, from fd_low (included) to fd_high (not included). The error will be ignored.
OS. curdir # the current directory is returned :('.')
OS. dup (fd) # copy the file descriptor fd
OS. dup2 (fd, fd2) # copy one file descriptor fd to another fd2
OS. environ # obtain system environment variables
OS. fchdir (fd) # change the current working directory through the file descriptor
OS. fchmod (fd, mode) # change the access permission of a file. The file is specified by the fd parameter, and the mode parameter is the file access permission under Unix.
OS. fchown (fd, uid, gid) # modify the ownership of a file. This function modifies the user ID and user group ID of a file, which is specified by the file descriptor fd.
OS. fdatasync (fd) # forcibly write the file to the disk. The file is specified by the file descriptor fd, but the file status information is not forcibly updated.
OS. fdopen (fd [, mode [, bufsize]) # create a file object through the file descriptor fd and return this file object
OS. fpathconf (fd, name) # Return the system configuration information of an opened file. Name is the value of the retrieved system configuration. It may be a string that defines the system value. These names are specified in many standards (POSIX.1, Unix 95, Unix 98, and others ).
OS. fstat (fd) # returns the state of the file descriptor fd, such as stat ().
OS. fstatvfs (fd) # returns information about the file system that contains the file descriptor fd, such as statvfs ()
OS. fsync (fd) # forcibly write the file with the file descriptor fd to the hard disk.
OS. ftruncate (fd, length) # crop the file corresponding to the file descriptor fd, so it cannot exceed the file size.
OS. getcwd () # Return to the current working directory
OS. getcwdu () # returns the Unicode object of the current working directory.
OS. isatty (fd) # If the file descriptor fd is open and connected to the tty (-like) device, true is returned; otherwise, False is returned.
OS. lchflags (path, flags) # mark the path as a number, similar to chflags (), but there is no soft link
OS. lchmod (path, mode) # modify the connection File Permission
OS. lchown (path, uid, gid) # change the file owner, similar to chown, but do not trace the link.
OS. link (src, dst) # create a hard link named dst, pointing to the src Parameter
OS. listdir (path) # Return the list of files or folder names in the folder specified by path.
OS. lseek (fd, pos, how) # set the current position of the file descriptor fd to pos. how to modify it: SEEK_SET or 0 to set the pos calculated from the file; SEEK_CUR or 1 is calculated from the current location; OS. SEEK_END or 2 starts from the end of the file. valid in unix and Windows
OS. lstat (path) # Like stat (), but there is no soft link
OS. linesep # The row Terminator used by the current platform. It is \ t \ n in win and \ n in Linux"
OS. major (device) # extract the device major number from the original device number (use st_dev or st_rdev field in stat ).
OS. makedev (major, minor) # Use the major and minor device numbers to form an original device number.
OS. makedirs (path [, mode]) # recursive Folder creation function. For example, mkdir (), but all the created intermediate-level folders must contain subfolders.
OS. minor (device) # extract the device minor number from the original device number (use st_dev or st_rdev field in stat ).
OS. mkdir (path [, mode]) # create a folder named path in the mode of the number. The default mode is 0777 (octal ).
OS. mkfifo (path [, mode]) # create a named pipe. The mode is a number and the default value is 0666 (octal)
OS. mknod (filename [, mode = 0600, device]) # create a file system node named filename (file, device special file, or pipe ).
OS. open (file, flags [, mode]) # open a file and set the required open options. The mode parameter is optional.
OS. openpty () # open a new Pseudo Terminal Pair. Returns the pty and tty file descriptors.
OS. pathconf (path, name) # Return the system configuration information of the relevant file.
OS. pathsep # string used to split the file path
OS. pardir # obtain the string name of the parent directory of the current directory :('..')
OS. pipe () # create a pipeline. A pair of file descriptors (r, w) are returned for reading and writing respectively.
OS. popen (command [, mode [, bufsize]) # open a pipeline from a command
OS. path. abspath (path) # returns the absolute path of path normalization.
OS. path. split (path) # splits the path into two groups of directories and file names.
OS. path. dirname (path) # Return the path directory. It is actually the first element of OS. path. split (path ).
OS. path. basename (path) # Return the final file name of the path. If the path ends with a slash (/) or slash (\), a null value is returned. That is, the second element of OS. path. split (path ).
OS. path. exists (path) # True is returned if path exists. False is returned if path does not exist.
OS. path. isabs (path) # If path is an absolute path, True is returned.
OS. path. isfile (path) # If path is an existing file, True is returned. Otherwise, False is returned.
OS. path. isdir (path) # If path is an existing Directory, True is returned. Otherwise, False is returned.
OS. path. join (path1 [, path2 [,...]) # returns the result after combining multiple paths. The parameters before the first absolute path are ignored.
OS. path. getatime (path) # Return the last access time of the file or directory pointed to by path
OS. path. getmtime (path) # Return the last modification time of the file or directory pointed to by path
OS. name # string indicates the current platform. Win-> 'nt '; Linux-> 'posix'
OS. read (fd, n) # reads up to n Bytes from the file descriptor fd and returns a string containing the read bytes. The file descriptor fd corresponds to the end of the file and returns an empty string.
OS. readlink (path) # returns the file to which the soft link points
OS. remove (path) # delete a file with the path. If path is a folder, OSError will be thrown; check the following rmdir () to delete a directory.
OS. removedirs (path) # recursively delete directories. If the directory is empty, delete it and recursively go to the upper-level directory. If the directory is empty, delete it.
OS. rename (src, dst) # rename a file or directory from src to dst
OS. renames (old, new) # recursively rename the directory or rename the file.
OS. rmdir (path) # Delete the empty directory specified by path. If the directory is not empty, an OSError exception is thrown.
OS. sep # The path delimiter specified by the operating system. In Windows, it is \, and in Linux, It is "/"
OS. stat (path) # obtains the information of the path specified by path, which is equivalent to the stat () System Call in C API.
OS. stat_float_times ([newvalue]) # determines whether stat_result displays a timestamp as a float object.
OS. statvfs (path) # obtain the statistics of the file system in the specified path
OS. symlink (src, dst) # create a soft link
OS. system ("bash command") # Run the shell command to directly display
OS. tcgetpgrp (fd) # returns the process group associated with the terminal fd (an opened file descriptor returned by OS. open ().
OS. tcsetpgrp (fd, pg) # set the process group associated with the terminal fd (an opened file descriptor returned by OS. open () to pg.
OS. tempnam ([dir [, prefix]) # Return the unique path name used to create a temporary file.
OS. tmpfile () # returns a file object in the open mode (w + B). This file object has no folder entry and no file descriptor, and will be automatically deleted.
OS. tmpnam () # returns a unique path for creating a temporary file.
OS. ttyname (fd) # returns a string that represents the terminal device associated with the file descriptor fd. If fd is not associated with a terminal device, an exception is thrown.
OS. unlink (path) # delete the file path
OS. utime (path, times) # returns the access and modification time of the specified path file.
OS. walk (top [, topdown = True [, onerror = None [, followlinks = False]) # output the file name in the folder to move up or down in the middle of the tree.
OS. write (fd, str) # write a string to the file descriptor fd. Return the length of the actually written string.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.