Packages
1. 结构
food_store/
__init__.py
product/
__init__.py
fruit/
__init__.py
apple.py
banana.py
drink/
__init__.py
juice.py
milk.py
beer.py
cashier/
__ini__.py
receipt.py
calculator.py
假设banana.py文件内容如下:
def get_available_brands():
return ['chiquita']
class Banana:
def __init__(self, brand='chiquita'):
if brand not in get_available_brands():
raise ValueError('Unkown brand: {}'.format(brand))
self._brand = brand
2. Import
from food_store.product.fruit.banana import Banana
my_banana = Banana()
from food_store.product.fruit import banana
brands = banana.get_available_brands()
my_banana = banana.Banana()