The role of the module: similar to the function, in order to avoid a large number of duplication of code generation, can be efficient to complete the work.
By importing a system or a module that someone else has already written, avoid repeating the wheel and quickly achieve the intended purpose.
A py file can be a module, and a function within a PY file can be a method of invocation.
Types of modules
Python Standard library
Third-party modules
Application Custom Modules
1. Methods used by the module
1.1
Import Test
In import, Python will find the path of the module through Sys.path, in addition to the system's built-in path, the executable directory will be added to the path,
So, if the test and execution files are in the same directory, you can get them directly through the import
Use the method inside test
Test.ceshi ()
1.2 From My_mudule Import test
This mymudule can be a path, for example from WEB.WEB1.WEB2 Import test
If Mymudule is and executes the file under the same folder, because this folder is already in the execution of the time to add to the path, so the direct write Mymudule,python can find this folder, but if not the folder to execute files, You need to fill in the path as above.
1.3 From Test import Ceshi
The function method is called directly from the file name in the sibling directory, so that the function can be used directly in the execution file;
Ceshi ()
1.4 Calling multiple modules at the same time
Can be time,test by import
Separated by commas to invoke simultaneously
2. Principles of Module invocation
When the module is called, the content used in the module is executed once
The role of 3.__name__
Call name in the execution file, the output is main, but not the execution of the file, but is called the file execution name, the output is the path of the file
Effect: 1. First, when you test a function file, you can first
if __name__ __main__ ():
In this case, the code underneath can run when the test is called, but when it is called, because import executes all the contents of the called file, this prevents the test code from being called
2. You can prevent your own bin execution file from being called
-------------
4.time Module
4.1 Import time Time module usage
4.1.1 Time.time () timestamp
Show timestamps, that's how many seconds from 1970 to now.
4.1.2 Time.localtime () structured time
Import Time Print (Time.localtime ())--time.struct_time (tm_year=2018, tm_mon=6, tm_mday=25, tm_hour=22, Tm_min=9, TM _sec=30, Tm_wday=0, tm_yday=176, tm_isdst=0)
4.1.3 String Time
4.2 Conversion between different time structures
4.2.1 Timestamp conversion to structure time
A=Time.localtime (Time.time ())print(a)------time.struct_time (tm_year= 2018, Tm_mon=6, tm_mday=25, tm_hour=22, tm_min=12, tm_sec=51, tm_wday=0, tm_yday=176, tm_isdst=0)
4.2.2 Structured time conversion to timestamp
A=Time.mktime (Time.localtime ())print(a)---1529940330.0
4.2.3 structured time converted to string time
Print (Time.strftime ('%y-%m-%d%x', Time.localtime ()))
4.2.4 string time conversion to structured time
Print (Time.strptime ('2016:6:18:23:15:40','%y:%m:%d:%x'))
4.3 Show current time directly
Time.actime ()
2018-06-25-python full Stack Development day21-part2-module Introduction