Introducing Modules
Grammar
Import Modename
one.py
def printsomething (str): print ("" + str);
main.py
Import oneone.printsomething ("jiao"); #hello jiaoone.printsomething ("fftu"); #hello FFTU
Partially introduced
Grammar
from modename import functionname, VarName
one.py
def printsomething (str): print ( "+"should go now ";d EF printbye (): print (str);
main.py
from One import printsomething, printbyeprintsomething ("jiao"); #hello Jiaoprintbye (); #you should go now
Note: Part of the introduction cannot use the module name one
In addition to the function, you can also introduce the variables of the module (do not introduce access errors, but the module function can access the variable)
All introduced (all functions and variables within the module are introduced into the current file)
Grammar
from one import *
The introduction of post-usage is the same as partial introduction
Dir () function
Returns all names defined in the module as a list of strings
Import Oneprint (dir (one));
#['__builtins__','__cached__','__doc__','__file__','__loader__','__name__','__package__','__spec__','printsomething','Printbye','str1']
No arguments return all names of the current file definition (the introduced module does not parse, only one name)
Import Onenuma=Ten; StrB="haha";p rint (dir ()); #['__annotations__','__builtins__','__cached__','__doc__','__file__','__loader__','__name__','__package__','__spec__','NumA',' One','StrB']
This parses the objects that are introduced into the module
fromOne import printsomething, Printbye, Str1numa=Ten; StrB="haha";p rint (dir ()); #['__annotations__','__builtins__','__cached__','__doc__','__file__','__loader__','__name__','__package__','__spec__','NumA','printsomething','Printbye','str1','StrB']
Standard modules
Python itself comes with some standard library of modules that will be introduced in the Python Library Reference document (that is, the library Reference document, later).
Some modules are built directly into the parser, which is not a feature built into the language, but can be used efficiently, even system-level calls.
These components are configured differently depending on the operating system, such as the WinReg module, which is only available to Windows systems.
python--Module