【发布时间】:2010-03-02 01:09:33
【问题描述】:
使用 pylons 0.9.7,我正在尝试创建一个按需连接到数据库的函数。我希望它可以从所有模型类中的所有函数访问。
在model/__init__.py,我有:
#Establish an on-demand connection to the central database
def connectCentral():
engine = engine_from_config(config, 'sqlalchemy.central.')
central.engine = engine
central.Session.configure(bind=engine)
此功能随处可用。但是,当我尝试在model/class.py 中指定的类中运行它时,它会返回:
NameError: global name 'connectCentral' is not defined
我必须做任何特殊的导入吗?有没有更好的方法来做到这一点?
谢谢。
【问题讨论】: