1、通过init.py 文件表明这个目录是一个Python包 2、可以更好的粘合各个模块
"""
module0
|card.py
|payment.py
|__init__.py
module1
|test.py
|__init__.py
"""
# card.py
class Cart:
def add_to_card(self):
print('Successfully added to cart')
# payment.py
class Payment:
def do_payment(self):
print('Payment Successfully done')
# module0/__init__.py
from .card import Card
from .payment import Payment
# test.py
# from module0.card import Cart
# from module0.payment import Payment
import module0
module0.Cart().add_to_card() # Successfully added to cart