0 introduction and overloading of basic python-modules

Source: Internet
Author: User

Knowledge Points:

1. A xxx.py is a module

2. Import the module is to read the contents of this file

3. The module is the core concept of Python, and large python programs are stacked with multiple modules, just like Lego bricks


Next, I'll put the demo code

Import Sysprint (sys.platform) # System platform Print (2**100) x= "Hello World \ n" Print (x*8) #打印8次temp =input ("Please enter") If temp==8:    Print ("Good luck") Else: print ("    bad Luck") print ("End")    

By running the above code, we will explain the following points of attention


Note the point:

1.import after + file name, without adding. py

2. File name note Do not bring "-", because sometimes do not pay attention to take it, otherwise there will be the following situation


As you can see, we can execute the python-ch3-001.py directly through the instructions, but in Python, it's not going through import.


Below, we copy python-ch3-001.py, named pythonch3001.py, that is, remove the middle "-", we look at the results


From the can see, the same code, different names, in the process of running a very different results, so we need to pay attention to the problem of naming


3. Import the same module, the first time the code is all running, the second time a lot of code is not running, in fact, the middle is just repeated execution


The Middle white box is where the second import is.

At the same time, we tried to modify the source file after the first import, and then import it the second time, the result is the same as the first one.


The reason is that the cost of the import operation is very large, it compiles the file into a byte code, and then the PVM to execute, in the process of compiling, consumes a lot of resources, so, the import operation is only compiled once, the second is only repeated execution, no longer compile


If you want to execute the complete code again, you need to reload () This function, he will reload the source code, and then execute it again, but before executing reload, must ensure that the module has been import

Also, execute the From IMP import reload before executing the reload, because reload is no longer a built-in function in Python3.



From can see, the first time reload, error, then import module, again reload only success

And there will be a print statement prompt after success


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

0 introduction and overloading of basic python-modules

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.