one, sys module1. Definition:
A module that interacts with the Python interpreter
2, sys module commonly used methods(1) sys.argv method
Definition: Command line Arguments list, the first element is the path of the program itself
Cases:
Import Sysprint (SYS.ARGV) # SYS.ARGV just reflects the current module name, with a list of # and Pycharm software automatically adds absolute path to us
Output: # This is not the right result, because it's pycharm.
['C:/users/william/pycharmprojects/python_item2/study/day12/sys module/argv method. py']
View Code
The result of the output shown in the terminal with this sys.argv method is the correct result:
Therefore, in the work, it must be the result of the output of the terminal to prevail
Focus:
SYS.ARGV commonly used to pass user input account number and password
Example 1:
Example 2:
In order to find the user name and password more conveniently, it is best to add "-U" and "-P" before the account password.
(2) Sys.exit () method
Definition: Exit the program, exit normally (0)
Cases:
An example that has been done before: there are 10 numbers when the loop to the number 8 o'clock exits the program
Sys.exit ()
Import Syscount = 1while count <: print (count) if Count = = 8: sys.exit () count + = 1print (' ending ')
Output Result:
12345678
View Code
(3) Sys.version method
Definition: Get version information for the Pyhon interpreter
(4) Sys.maxint method
Definition: the largest int value
(5) Sys.path method
Definition: Returns the search path of the module, initializing the value using the PYTHONPATH environment variable
Example 1:
Import Sysprint (Sys.path) # Get the search path for the module
Output Result:
['C:\\users\\william\\pycharmprojects\\python_item2\\study\\day12\\sys Module','c:\\users\\william\\pycharmprojects\\python_item2','C:\\python\\python36\\python36.zip','C:\\python\\python36\\dlls','C:\\python\\python36\\lib','c:\\python\\python36','c:\\users\\william\\appdata\\roaming\\python\\python36\\site-packages','c:\\python\\python36\\lib\\site-packages']
View Code
To add an environment variable:
Example 2: Use Sys.path to add a custom module1.py module to a python environment variable.
(6) Sys.platform method
Definition: Returns the operating system platform name
Cases:
second, logging module1. Definition
Log module
2. Common methods of logging module
(1) Logging.debug () method
(2) Logging.info () method
(3) logging.warning () method
(4) Logging.error () method
(5) Logging.critical () method
third, the JSON module
Four, pickle module
Python Foundation 13th day--sys module, logging module, JSON module, pickle module