How can I use Python namedtuples to insert rows into mySQL database -
i have used namedtuples read rows mysql ... great. can use same mechanism insert rows mysql. system changing quite bit, need simple way map python values columns in database, without having check order of values/columns every time change program using mysqldb library - change
namedtuple insert queries behave normal tuples, have maintain order of column/values. can use named placeholders , dicts avoid that.
cursor.execute("insert person (name, age) values (%(name)s, %(age)s)", {"name": "bernard", "age": 30})
related question: python mysqldb: query parameters named dictionary
Comments
Post a Comment