Python tips Module

Source: Internet
Author: User

When using import to import a module, the module name is the Python file name, removing the suffix. py.


When importing a module, the program in this module will be executed, but it will only be executed during the first import. If it is re-imported later, it will not be executed. If it needs to be re-executed, you can call the built-in function reload ().


If you want a program in the Python file not to be executed when the file is imported as a module, you can place the program in the if statement below:

If _ name _ = '_ main __':

In this way, only when the file is executed in an independent program will the programs in if be executed. This is because each file has a built-in attribute _ name __. if the file is executed in an independent program, _ name _ is set to '_ main __', if the file is imported as a module, _ name _ is set to the module name.


To introduce non-standard modules, run the following command to install them (for Ubuntu ):

Apt-get install python-tkapt-get install python-mysqldbapt-get install python-numpyapt-get install python-scipyapt-get install python-matplotlib

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.