-
-
Save rogeruiz/2853250 to your computer and use it in GitHub Desktop.
MySQL insert using double list comprehension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def reward_close(data): | |
fields = ['id','name','image_url','hint','message','type','allow_duplicates','active'] | |
print "Processing %i rewards" % len(data) | |
c.executemany( """INSERT INTO `ford_post_season`.`bv_rewards` (`%s`) VALUES (%s)""" % ('`, `'.join(fields), ', '.join(['%s'] * len(fields))), | |
[[reward[field].encode('utf-8') if hasattr(reward[field], 'encode') else reward[field] for field in fields] for reward in data]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment