large python programs are organized in the form of modules and packages. The Python standard library contains a large number of modules. A python file is a module.
1. Standard module
python comes with no need for you to install
2. Third-party modules
needs to be installed, provided by others.
pip install XXX automation installed
Manual Installation
Download the installation package First
Unzip
in the command line into the directory after the decompression
Execute python setup.py install
3. Write your own
python files that you write yourself
Import XX Imports a file, what is the essence of the import file, run this python once
Import hahaha
Import When importing the file, first find the file from the current directory.
and then from the python environment variable inside to get a command, regardless of which directory can be executed
Import SYS
print (Sys.path) #查看当前系统的环境变量
4. Common Modules
ImportOSPrint(OS.GETCWD ())#fetch Current Working directoryPrint(Os.chdir (".."))#change the current directoryPrint(OS.GETCWD ())#fetch Current Working directoryPrint(Os.curdir)#current directory, relative pathPrint(Os.pardir)#parent directory, relative pathPrint(Os.mkdir ("test1"))#Create a folderPrint(Os.rmdir ("test1"))#only empty folders can be deletedPrint(Os.remove (".. /day4/5.png"))#Delete file, cannot delete folder. Print(Os.listdir ('c://'))#list all files in one directoryOs.rename ("Test","test1")# RenamingPrint(Os.stat ("notes. txt"))#Get file InformationPrint(__file__)#__file__ is the absolute path to this file.Print(Os.path.abspath (__file__))#Get absolute pathPrint(Os.path.split ("C:\\usr\\hehe\\hehe.txt"))#split path and file namePrint(Os.path.dirname ("C:\\usr\\hehe\\hehe.txt"))#Get Parent DirectoryPrint(Os.path.basename ("C:\\usr\\hehe\\hehe.txt"))#gets the last level, if the file displays the filename, if the directory displays the directory namePrint(Os.path.exists ("C://test2"))#whether the directory/file existsPrint(Os.path.isfile (R"E:\txz\day2.zip"))#determine if it is a filePrint(Os.path.isdir (R"E:\txz\day2"))#is a folderName ='A.sql'Print(Os.path.join ("e", name))#stitching into a pathPrint(OS.SEP)#path delimiter for current operating systemPrint(OS.LINESEP)#line breaks for the current operating systemPrint(OS.PATHSEP)#The delimiter for each path in the current system's environment variables, Linux is:, Windows is;Print(Os.environ)#environment variables for the current systemPrint(Os.name)#Current system namec://java/jre;c://python/usr/local:/Rootos.system ('dir')#used to execute operating system commands, can only execute, get no resultsres = Os.popen ('ipconfig')#used to execute operating system commands, and gets the results returned. ReadPrint(Res.read ())#ConstantsImportSYSPrint(Sys.path)#Environment VariablesPrint(Sys.platform)#See what the current system isPrint(sys.version)#look at the python versionPrint(Sys.exit ('Program Exit')) Quit ('Program Exit')#Exit ProgramPrint('hahaha')defFun (a):PassPrint(SYS.ARGV)#is to get the parameters passed in when the Python file is runPython xxx.py
5. Encryption Module
Import Hashlib def Md5_password (st:str):# defines the type of the input parameter and can only be converted to a binary type in string type # # Encrypt return # returns the encrypted result
6. Random Number Module
Importrandom,stringPrint(Random.randint (1,199))#1-199 randomly take an integerPrint(string.digits)#all the numbers 0-9Print(string.ascii_lowercase)#All lowercase lettersPrint(string.ascii_uppercase)#All uppercase LettersPrint(string.ascii_letters)#all lowercase letters + all uppercase lettersPrint(string.punctuation)#all the special characterss= Random.choice (['YBQ','MPP','Zhx','DF'])#randomly take an elements = Random.choice ()#randomly take an elementres = random.sample (string.digits,3)#randomly fetch n elementsPrint("'. Join (RES)) Res= Random.uniform (1,9)#take random decimals?? Print(RES)Print(Round (res,2))#keep a few decimals, and if the last decimal number is 0 after rounding, do not showPrint(Random.random ())#take a random decimal between 0-1s= ['a','b','C','D','e']random.shuffle (s)#Shuffle, scramble order, only listPrint(s)
Python Learning Notes (eight)-modules