我寫了一個非常簡單的SQLite選擇函數,但我很困惑如何傳遞成員函數......例如:.fetchone()
,.fetchmany()
。將成員函數作爲函數arg傳遞?
def select(cursor, select="*", table="reuters", fetch=".fetchone()", tologfile=False, logfile=""):
if tologfile:
logfile = open(logfile, 'w')
logfile.write(str(cursor.execute("select * from ?;".replace('?',table).replace("select * ", "select "+select)).fetchone()))
logfile.close()
else: return str(cursor.execute("select * from ?;".replace('?',table).replace("select * ", "select "+select)).fetchone())
如何傳遞這個成員函數作爲ARG?
或者,你可以使用'func = a.test'。 lambda是不必要的。 – Ben