Brief Introduction to Python modules and packages

Source: Internet
Author: User

Brief Introduction to Python modules and packages
We often use packages written by others. If we use Python3.4 and install it in the C root directory of windows, the external packages are generally placed in: C: \ Python34 \ Lib \ sit-packages. py files exist separately, and there are packages in folders. Let's briefly talk about the modules and packages in Python. After reading them, we may be more clear about this directory. I. Module:. py, put it in C: \ Python34 \ Lib \ sit-packages, and write the following code: print ('this is ') then we can reference. py file, here. py is called a module. Compile the file: test. py, the Code is as follows: print ('Hello World') after running, the result is: hello world modify test. py code: 12 import aprint ('Hello World') after running, the result is: this is ahello world. Because we have added import a in the code, we will first execute. the code in the py module. Here, we can add a reference. the module File ending with py can also be referenced. pyc. pyo. pyd. so. what are the differences between the dll suffix module files? For an answer on the internet, refer to: 2. If there are many packages. py module files, which can be stored in a single folder for easy management. Under C: \ Python34 \ Lib \ sit-packages, create a folder named Test and create B under the folder named Test. py c. py, respectively write the code: print ('B') and print ('C'), modify test. the py code is import Test. bprint ('Hello World') this is bhello world 3. Add _ init _ to the package __. in The py file, many packages contain _ init __. py file, we also create this file in the Test folder, enter the code: print ('this is init '), and run test again. py. The result is: this is initthis is bhello world visible, add _ init __. after the py file is imported, the system runs _ init __. code 4 in py. If you want to create a sub-package in the package, create the childTest folder in the Test folder in the same way. py file. Now open C: \ Python34 \ Lib \ sit-packages. Do you feel familiar with it?

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.