A. py file can be seen as a module that resembles a class library encapsulated in other languages
Module Categories:
Built-in Modules
Custom Modules
Third-party modules (need to be installed to use)
I want to use the functions defined in cal.py, I can do this
For example: cal.py source code:
#!/usr/bin/python#coding:utf-8def Add (A, B): return a + b
import_test.py to use the Add function:
' #!/usr/bin/python #coding: Utf-8 import cal print Cal.add (10, 20) '
Second, built-in properties name
cal.py
' #!/usr/bin/python
#coding:utf-8 def add ( a, b ): return a + b print __name__ [email protected]:~/python$ python cal.py
main
[email protected]:~/python$ python Import_ test.py
Cal
[email protected]:~/python$
#!/usr/bin/ python #coding:utf-8 def add ( a, b ): return a + b if __name__ == ' __main__ ':p rint add ( 100 , 200 ) [email protected]:~/python$ python import_test.py [email protected]:~/python$ python cal.py300 '
This is a small function of name , when a module (. py file) is called by another file, it is generally wanted to invoke the function or method defined inside it, we can make the external module call mode by name , and will not execute to a similar print add ( 100, 200) such a specific business code. Only the function or method definition inside is used.
Cylindrical Templates
Python module using method notes