Online offline Python apps

Sam Raker sam.raker at gmail.com
Thu Apr 23 05:01:35 CEST 2015


Have you tried a conditional/try-catch block in your __init__? Something like 

    class MyDBConn(object):
        def __init__(self, **db_kwargs):
            try:
                db = some_db.connect(**db_kwargs)
            except some_db.ConnectionError:
                db = my_fake_db() 
            finally:
                self.db = db 

You might have to write an adapter to make sure you can treat the fake db and real db the same way, but that shouldn't be too hard. 



More information about the Python-list mailing list