Skip to content

Instantly share code, notes, and snippets.



Created Jul 15, 2016
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())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment