I’m using Pylons + Python and am trying to figure how how to connect to our central database server only when necessary.
I created a class called Central() which I would like to instantiate whenever a connection to the central database server is necessary, e.g.:
class Central():
def __init__(self):
engine = engine_from_config(config, 'sqlalchemy.central.')
central_db = create_engine(engine)
print central_db
However this doesn’t work when I call:
c = DBConnect.Central()
What is the proper code for doing this?
Thanks.
Since I can’t tell what’s the layout of your code, I can only assume that you’ve got
engineandcentral_dbdefined somewhere in the global context. Is that correct? If so you could try something like this:It will reference global
engineandcentral_dbobjects instead of local ones (as Wim described)