Modules in Python

Source: Internet
Author: User

To make the code reusable, please modularize it!

Module is a program

Importing module Import sys

Tell the interpreter where to look for the module: sys.path.append (' Directory for module storage ')

Importing a module does not mean that some operations (such as printing text) are performed at the time of import, and they are used primarily for definition, such as variable functions or classes

When the module is imported, the import module once and the import module multiple times the effect is the same

Why is it? Because there will be two modules imported to each other, a import b,b import a,a import b,b Import a ...

Into a dead loop because nothing happens when you import the module for the second time, so the loop terminates

At that time, if you had to reload the module, you could use the built-in reload function, which has a parameter (the module to re-like) and returns the module again

Named modules: plus the suffix name of the. Py

Package: The package is the directory where the module is located, in order for Python to treat it as a package must contain a file named __init__.py (module) within the package

This article is from the "Make a few" blog, be sure to keep this source http://9399369.blog.51cto.com/9389369/1605278

Modules in Python

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.