Using pylons 0.9.7, I'm trying to make a function that connects to a database on demand. I'd like it to be accessible from all functions within all model classes.
In model/__init__.py
, I have:
#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)
This function is accessible everywhere. However, when I try to run it from within a class specified in model/class.py
, it returns:
NameError: global name 'connectCentral' is not defined
Do I have to do any kind of special import? Is there a better way to do this?
Thanks.