# 和数据库建立连接
    connecter = MySQLdb.connect(
        host='127.0.0.1',
        port=3306,
        user='root',
        password='110396',
        db='restframework'
    )
    cursor = connecter.cursor()
    cursor.executemany(sql, info_dict)
    connecter.commit()
	

------------
class BaseCursor:
    def executemany(self, query, args):
    # type: (str, list) -> int
    """Execute a multi-row query.
	if not args:
	    return

        m = RE_INSERT_VALUES.match(query)
        if m:
            q_prefix = m.group(1) % ()
            q_values = m.group(2).rstrip()
            q_postfix = m.group(3) or ""
            assert q_values[0] == "(" and q_values[-1] == ")"
            return self._do_execute_many(
                q_prefix,
                q_values,
                q_postfix,
                args,
                self.max_stmt_length,
                self._get_db().encoding,
            )

        self.rowcount = sum(self.execute(query, arg) for arg in args)
        return self.rowcount

在多条插入语句中参数是放在列表中的元组

posted on 2021-06-24 16:55  x-dai  阅读(109)  评论(0编辑  收藏  举报