Online offline Python apps

Sam Raker sam.raker at
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):
                db = some_db.connect(**db_kwargs)
            except some_db.ConnectionError:
                db = my_fake_db() 
                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