Python chapter Nineth modules and Packages (2)

Source: Internet
Author: User

1. If there is no __init__.py file under the file, the program will not consider this to be a python package.

2. This is required if you want to use the From package import *. The file that contains the method in the module does not contain a class:

#coding =utf-8
Import A
A.say ()
From Import b
B.say ()


Use from Bao Import *

Write under __init__.py file: __all__==[' A ', ' B '] where a B is the file name under this package

3. Examples introduced when a class is included in a module

#     The 1th approach introduced

From Bao2Import a
from bao2 Import b
A.a.say ()
B.b.say ()
#引入的第二种方式
from bao2.a import a
from bao2.b import b
A.a.say ()
B.b.say ()
# 3rd method introduced
from bao import *
A.say ()
B.say ()
The third way to do before you need to write the following content
What the __init__.py file inside the Bao2 needs to write
#coding =utf-8
Import a (Class A)
Import b (class B)

Python chapter Nineth modules and Packages (2)

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.