Python calls a custom module method Python Training Center

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.