python calls a custom module method python Training center
Pythonmodule is aPythonfiles, to. PYThe end, including thePythonObject Definitions andPythonstatement that enablesPythoncode Snippets are more logical, better, and easier to understand, sincePythonmodule has so many benefits, then how to referencePythonWhat about the module?
im Port statement
custom modules can be introduced using import statements, the procedure is to import the module first, then call the function contained in the module, you can put the custom module into the current directory, to facilitate the interpreter path search, the following is the import of custom hello.py module, and invoke The instance of the world function:
#!/usr/bin/python
#-*-Coding:utf-8-*-
# Import Module
Import Hello
# Now you can invoke the functions contained in the module.
support.print_func ("World")
The output is:
Hello World!
The above examples can also be used from... Import method is implemented by importing the specified part from a module into the current namespace, which can be written as:
#!/usr/bin/python
#-*-Coding:utf-8-*-
From Hello to import world
If you want to import all the contents of the module into the current namespace, you can use the from... import* The following are examples of the methods:
#!/usr/bin/python
#-*-Coding:utf-8-*-
From Hello Import *
also note that when you want to import a module, The Python interpreter searches the location of the module, with the following sequence of searches:
1. current directory;
2. If it is not in the current directory,Python searches for each directory under the shell variable PYTHONPATH;
3. If none are found, Python will look at the default path.
more Python -related knowledge learning, you can search "old boy education python Training" into the official website to study, can also be contacted by the following ways to learn.
Python calls a custom module method Python Training Center