One, the module five most
Definition, importing method, import essence (path Search), import optimization, module classification
1. Definition:
Modules are used to logically organize Python code (variables, functions, classes, logic to implement a function), which is essentially the. Py end of the Python file
2. How to Import
(1) Import module_name1,module_name2
Import multiple words, separated by ","
(2) from Module_alex Import * (Import all functions inside the module, not recommended)
or from Module_alex import m1,m2,m3
(3) from Module_alex import logger as Logger_alex
Alias mechanism, imported module logger from the individual name Logger_alex, reference logger_alex.xxx
3. Import Essence
(1) Interpret all Module_alex code once, assign to Module_alex (All_Code), use module_alex.xxx when calling
(2) from ... import name
Directly open the name variable in the Module_alex file, get the current explanation and execute it again, calling name directly
Summary: The essence of the import module is to interpret the Python file again
(3) Python package: The essence is a directory (must contain the __init__.py file), logically organize the module
The essence of the import package is to interpret the __init__.py file under the Execute Package
Process: Search Module--Find module--Explain execution
Search for the environment variable defined by Sys.path (), find it and not go back.
4. Import optimization
From module_test Import test
If the method is used too much, it is recommended to use the method above
5, the classification of the module
Standard library (built-in module), open source module, custom module
Second, built-in modules
(1) Time and datetime
A, time stamp
B. Formatted time string
C, tuple (struct_time) a total of nine elements
Method: Time.time () timestamp
Time.clock
Time.sleep () Sleep for a few seconds
Time.gmtime () Convert Narimoto Group (Greenwich time Zone)
Time.localtime () turn into tuples (local area)
Time.mktime () tuple converted to timestamp
Time.strftime () tuples converted into words
Time.strptime () string to tuple (note one by one correspondence)
Asctime () tuple to string (specific format)
CTime () timestamp to string (same format as above)
The fifth day of the Python devops development