How does python reference the Python module
This article introduces the relevant knowledge of "how to quote the Python module from python". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Import statement
The custom module can be introduced using the import statement. The operation step is to import the module first, and then call the functions contained in the module. You can put the custom module into the current directory to facilitate path search of the interpreter. The following is an example of importing a custom hello.py module and calling the World function:
#! / usr/bin/python
#-*-coding: UTF-8-*-
# Import module
Import hello
# now you can call the functions contained in the module
Support.print_func ("World")
The output is as follows:
Hello World!
From can also be used for the above examples. Import is implemented by importing the specified part from a module into the current namespace. The above functions can be written as follows:
#! / usr/bin/python
#-*-coding: UTF-8-*-
From hello import World
If you want to import everything in the module into the current namespace, you can use from... The method of import*. Specific examples are as follows:
#! / usr/bin/python
#-*-coding: UTF-8-*-
From hello import *
Also note that when you import a module, the Python interpreter searches the location of the module in the following order:
1. Current directory
two。 If it is not in the current directory, Python searches each directory under the shell variable PYTHONPATH
3. If neither is found, Python looks at the default path.
This is the end of the content of "how to quote the Python module from python". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!