I want to make my own MagicCursor class. I want it to inherit all method and attributes from sqlite3.Cursor(). But it looks not that easy in t his case.
usually we create a cursor like this:
import sqlite3
conn = sqlite3.connect('test.db')
crs = conn.cursor()
because there's a connection in between. So I think I have to define my own Connection Class and then define my own Cursor.
Here's what I want to implement:
import sqlite3
conn = MyConnect('test.db') ## this returns me a connect object, inherit from sqlite3.Connection
crs = conn.cursor() ## this returns me a MyCursor class,
## which inherit from sqlite3.Cursor() and has my customized method
Here's my code, but failed.
class MyConnect(sqlite3.Connection):
def cursor(self):
return MyCursor(self)
class MyCursor(sqlite3.cursor):
def __init__(self, connect):
self = connect.cursor()
def mymethod1(self, argv)
...... return ...... ## what ever I defined
Anyone got an idea how to implement that?