Python3 OS module & sys module & hashlib module, python3os Module
1 '''2 OS Module 3 very important module 4 '''5 import OS 6 # print (OS. getcwd () # Get the current working directory 7 # OS. chdir (r 'pathname') # change the current working directory 8 # print (OS. curdir) # returns the current directory ,'. '9 # print (OS. pardir) # obtain the parent directory name (string) of the current directory ),'.. '10 # OS. makedirs ('. \ sss \ sss') # generate folders and recursively generate them (I use Windows) 11 # OS. removedirs ('. \ sss \ sss') # delete a folder. Only empty folders can be deleted (Windows is used) 12 # OS. mkdir ('bob') # generate a folder and do not recursively generate 13 # OS. rmdir ('. \ bob ') # delete a folder. The folder cannot be recursive. 14 # print (OS. listdir (R' never On the path ') # list the folders and files under this path 15 # OS. remove ('') # delete a file. Folder 16 # OS cannot be deleted. rename ('old name', 'new name') # rename, similar to mv command 17 # OS in Linux. stat ('absolute file path') # Get File/directory information 18 # OS. sep # specify the path delimiter of the output operating system. In win, the path is \, and in Linux, the path Delimiter is/. 19 # OS. linesep # output the line terminator used by the current platform. In win, it is \ t \ n, and in Linux it is \ n 20 # OS. pathsep # output the string 21 # print (OS. name) # The output string indicates the current platform. Windows displays 'nt '; Linux displays 'posix' 22 # OS. system ("bash command") # Run the shell command to directly display 23 # OS. environ # obtain the system environment variable 24 # OS. path. abspath ('path') # returns the path normalized absolute path 25 # OS. path. split ('path') # split path into two groups of directories and file names and return 26 # OS. path. dirname ('path') # returns the path directory. In fact, it is the first element 27 # OS. path. basename ('path') # of OS. path. split (path) that returns the final file name of path. If the path ends with a slash (/) or slash (\), a null value is returned. That is, OS. path. the second element 28 # OS. path. exists ('path') # returns True if path exists; returns False29 # OS if path does not exist. path. isabs ('path') # If path is an absolute path, return True30 # OS. path. isfile ('path') # returns True if path is an existing file. Otherwise, False31 # OS. path. isdir ('path') # True is returned if path is an existing Directory. Otherwise, False32 # OS is returned. path. join (['path 1', 'path 2',...]) # If multiple paths are combined, the parameters before the first absolute path are ignored. 33 # OS. path. getatime ('path') # returns the last access time of the file or directory pointed to by path 34 # OS. path. getmtime ('path ') # Return the last modification time of the file or directory pointed to by path 35 36 37 38 ''' 39 sys module 40 Python interpreter for interaction 41 ''' 42 43 import sys44 # print (sys. argv) # List of command line parameters. The first element is the program path 45 # sys. exit (0) # exit the program. exit (0) when the program Exits normally, and errors exist from 1 to 12. 46 # print (sys. version) # obtain the version information of the Python interpreter 47 # print (sys. maxint) # maximum Int value 48 # print (sys. path) # search for the module path. When initializing, use the PYTHONPATH environment variable value 49 # print (sys. platform) # display the current operating system platform name 50 51 52 ''' 53 hashlib module 54 convert plaintext into a ciphertext (encrypted) 55''' 56 57 import hashlib58 # md559 # c1 = hashlib. md5 () 60 # print (c1) 61 #62 # c1.update ('Welcome to China '. encode ('utf-8') # convert the encoding to UTF-8. In Python3, the string is Unicode, python3 uses UTF-8 encoding 63 by default # update c1 content 64 # print (c1.hexdigest () # generate 65 # c1.update ('bob '. encode ('utf-8') 66 # print (c1.hexdigest () # New ciphertext 67 #68 # c2 = hashlib. md5 () 69 # c2.update ('yeah '. encode ('utf-8') 70 # print (c2.hexdigest () 71 72 73 # sha74 # c3 = hashlib. sha256 () #256 generally, more 75 # c3.update ('ads '. encode ('utf-8') 76 # print (c3.hexdigest ())