illumi
illumi

Reputation: 284

How do I extend a python module to include extra functionality? (sqlite3)

How would I extend the sqlite3 module so if I import Database I can do Database.connect() as an alias to sqlite3.connect(), but define extra non standard methods?

Upvotes: 1

Views: 217

Answers (2)

Markus Unterwaditzer
Markus Unterwaditzer

Reputation: 8244

You could write your own Database module that has the following line at the top:

from sqlite import *

Then define methods as you like, but make sure you don't overwrite anything.

Upvotes: 1

glglgl
glglgl

Reputation: 91149

You can create a class which wraps sqlite3. It takes its .connect() method and maybe others and exposes it to the outside, and then you add your own stuff.

Another option would be subclassing - if that works.

Upvotes: 4

Related Questions