Friday 15 May 2015

mysql - how to call `getattr()` to get a Python MySQLCursor method? -



mysql - how to call `getattr()` to get a Python MySQLCursor method? -

what need do before, create python phone call succeed:

>>>getattr(mysqlcursor, "fetchall")

if create phone call @ origin of script, fails. have cursor , need programmatically obtain 1 of it's methods, such fetchall() string, such "fetchall" don't understand how setup phone call succeeds.

getattr(mysqlcursor, "fetchall") work:

>>> mysql.connector.cursor import mysqlcursor >>> getattr(mysqlcursor, 'fetchall') <unbound method mysqlcursor.fetchall>

so there is, unbound method within class mysqlcursor.

if have instance of cursor, can bound method, can call:

>>> mysql.connector.cursor import mysqlcursor >>> cursor = mysqlcursor() >>> cursor <mysql.connector.cursor.mysqlcursor object @ 0x7f9368a86350> >>> getattr(cursor, 'fetchall') <bound method mysqlcursor.fetchall of <mysql.connector.cursor.mysqlcursor object @ 0x7f9368a86350>> >>> getattr(cursor, 'fetchall')()

python mysql

No comments:

Post a Comment