sys modify environment variables
----------
Only temporary modification
SYS Import
sys.path.append ()
Example:
import sys sys.path.append('C:\Users\hualong\PycharmProjects\test\day21\test.py')
To permanently modify, you need to change the environment variables in the System Properties
Add the absolute path:
import sys,os if __name__ == '__main__': BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) sys.path.append(BASE_DIR)
OS module
- Get current working path
print(os.getcwd())
- Change the current working path
the os.chdir ( ' test0 ' ) into test0 # folder, return to the previous os.chdir ( '..')
---other
os.path.exists (path) # If the path exists returns True, otherwise return False os.path.isabs (path) # If the path is an absolute path, returns True os.path.isfile (path) # If the path is an existing file returns True os.path.isdir (path) # If the path is an existing directory, returns True os.path.join (path1, path2, ....) # multiple return paths after stitching os.path. getatime (path) # returns the last access time of the file or directory pointed to by path os.path.getmtime (path) # returns the path of the file or directory pointed to by the last modified time
os.makdirs ( ' main / MAIN1 ' ) # generate a multi-layer recursive directory os.removedirs ( ' main / MAIN1 ' ) # delete main1 (only delete empty folders, if the main is empty delete) os.mkdir () # generate single-level directory os.rmdir () # delete a single stage empty directory os.listdir () # list all files and subdirectories in the specified directory the os.stat () # description file specified information os.sep # output specified operating system the path separator os.linesep # outputs the current line terminator platform os.pathsep # output file path character string for dividing the os.name # output string is simply the name of the current platform os.system () # display commands such as: dir information os.path.split () # split into a directory path and file name tuple back os.path.dirname () os.path.basename ()
sys module
. 1 the sys.argv # command line parameter list, the first element of the program itself path 2 the sys.exit (n-) # exits the program, exit (0) when the normal exit . 3 The sys.version # obtain python interpreter version information . 4 SYS. maxint # maximum value of Int 5 sys.path # return module search path 6 sys.platform # return the name of the operating system platform
Progress sub-regulations:
import sys,time for i in range(100): sys.stdout.write('#') time.sleep(1) sys.stdout.flush()