1

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?

2
  • 3
    Why do you need that? Python is dynamic, so you can add extra functions and methods and whatnot to modules, but that does not mean that that is a good idea. Create your own module for that code instead. Commented Dec 14, 2012 at 15:25
  • End users are sometimes not the brightest of people, so having a module which is an alias to the built in stuff but also with all the extra functionality I require would be an ideal situation. Commented Dec 14, 2012 at 15:50

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.