Skip to content

Instantly share code, notes, and snippets.

@danapplegate
Created June 1, 2012 16:08
Show Gist options
  • Save danapplegate/2853235 to your computer and use it in GitHub Desktop.
Save danapplegate/2853235 to your computer and use it in GitHub Desktop.
MySQL insert using double list comprehension
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