【发布时间】:2015-05-28 18:01:16
【问题描述】:
使用在抽象类的基类中导入的函数的正确方法是什么?例如:在base.py 我有以下内容:
import abc
import functions
class BasePizza(object):
__metaclass__ = abc.ABCMeta
@abc.abstractmethod
def get_ingredients(self):
"""Returns the ingredient list."""
然后我在diet.py中定义方法:
import base
class DietPizza(base.BasePizza):
@staticmethod
def get_ingredients():
if functions.istrue():
return True
else:
retrun False
但是,如果我尝试运行
python diet.py
我得到以下信息:
NameError: name 'functions' is not defined
如何让diet.py 识别base.py 导入的库?
【问题讨论】:
-
再次导入模块或委托给方法有什么问题?
-
...你说
from base import functions -
我认为
import base.py也不是有效的 python .... 除非你的文件布局真的很不稳定
标签: python python-3.x abstract-class abc