如何将游戏数据导出到MySQL?

时间:2010-06-19 19:28:41

标签: python mysql google-app-engine download

我有'大学'模型数据。

我的str_loader.py是:

class MySQLExporter(bulkloader.Exporter):
    def output_entities(self, entity_generator):
        conn = MySQLdb.connect(host='localhost',user='root',passwd='root',db='test',charset="utf8")
        c = conn.cursor()
        for entity in entity_generator:
          c.execute("INSERT INTO haha (a,b) VALUES (%s, %s)",
                    (entity['cid'], entity['name']))

class Mysql_download(MySQLExporter):
    def __init__(self):
        MySQLExporter.__init__(self,'College',
                                   [
                                    ('cid', str,None),
                                    ('name', lambda x: unicode(x, 'utf8'),None),
                                   ])

exporters = [Mysql_download]

它运行成功。但是,它不会向MySQL插入数据。

1 个答案:

答案 0 :(得分:1)

加载实体后尝试在连接上调用.commit()