python os, sys module

 os module is responsible for programs interact with the operating system, provides the interface to access the underlying operating system;
 SYS responsible for interacting with the python interpreter program module that provides a set of functions and variables to control when running python environment.

 

<Os common method>

os.remove ( 'path / filename') Delete File

os.rename (oldname, newname) rename files

os.walk () generated directory tree of all the file names

os.chdir ( 'dirname') change the directory

os.mkdir / makedirs ( 'dirname') to create the directory / multi-directory

os.rmdir / removedirs ( 'dirname') delete the directory / multi-directory

os.listdir ( 'dirname') listed in the specified directory file

os.getcwd () Get current working directory

os.chmod () to change the directory permissions

os.path.basename ( 'path / filename') removing the directory path, file name returned

os.path.dirname ( 'path / filename') to remove the file name, directory path returned

os.path.join (path1 [, path2 [, ...]]) isolated a packet combining each part pathname

os.path.split ( 'path') return (dirname (), basename ()) tuple

os.path.splitext () returns (filename, extension) tuple

os.stat ( 'path') returns the file properties of an object, you can view the file permissions, size, creation time, modification time, etc.

os.path.getatime \ ctime \ mtime return the recent visit, create, modify time

os.path.getsize () Returns the file size

os.path.exists () if there is

os.path.isabs () whether or not an absolute path

os.path.isdir () whether the directory

os.path.isfile () whether the file

 

<Sys common method>

sys.argv command line parameters List, the first element is the path to the program itself

sys.modules.keys () returns a list of all modules has been introduced

the sys.exc_info () Gets exception class currently being processed, the detailed abnormality information exc_type, exc_value, exc_traceback currently processed

sys.exit (n) to exit the program, when the normal exit exit (0)

sys.hexversion get version value Python interpreter, hexadecimal formats such as: 0x020403F0

sys.version get Python interpreter version information

sys.maxint maximum value of Int

sys.maxunicode largest Unicode value

sys.modules return module field of system implementation, key module name, value module is

sys.path return path search module, using the value of environment variable initialization PYTHONPATH

sys.platform return the name of the operating system platform

sys.stdout standard output

sys.stdin standard input

sys.stderr error output

sys.exc_clear () to clear the current thread that appears in the current or most recent error message

sys.exec_prefix return python platform-independent file installation location

Sys.byteorder local rule pointer byte, the value of the platform is big-endian 'big', the value of little-endian platform is 'little'

sys.copyright record python copyright-related stuff

C API version of sys.api_version interpreter

sys.stdin,sys.stdout,sys.stderr

Quoted from: https: //www.cnblogs.com/big-devil/p/7625910.html

Guess you like

Origin www.cnblogs.com/lides/p/11115803.html