【发布时间】:2010-09-14 22:21:49
【问题描述】:
我想在一个类中使用导入,然后由另一个类继承,这样我就不必在每个文件中手动定义我的导入。我正在尝试这样但它不起作用,任何建议表示赞赏:
class Djangoimports ():
def __init__(self):
from django.template import Context
print Context
class Init1 (Djangoimports):
def __init__(self):
Djangoimports.__init__(self)
self.c = Context(self.constructor_dict) # just example of trying to use the imported "Context"
>>>>> global name 'Context' is not defined
我已经尝试过尝试使用“self”的变体,但无法弄清楚如何在 import from 中适当地使用它,因为它与我通常使用“self”的类属性/方法不同
【问题讨论】:
标签: python django class import