Skip to content

Instantly share code, notes, and snippets.

@fengxsong fengxsong/test.py
Created Jul 15, 2016

Embed
What would you like to do?
#!/usr/bin/env python
import os
BASEDIR = os.path.dirname(os.path.abspath(__file__))
filenames = [f for f in os.listdir(BASEDIR) if os.path.splitext(f)[1] == '.txt']
for filename in filenames:
fn, ext = os.path.splitext(filename)
left, _ = fn.split('-')
with open(filename) as fr:
with open(fn+'.sql', 'a+') as fw:
for l in fr:
sql = "INSERT INTO table (`value1`,`value2`,) VALUES ('{value1}','{value2}');\n".format(value1=left, value2=l.strip())
fw.write(sql)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.