Skip to content

Instantly share code, notes, and snippets.

@Achifaifa
Created July 9, 2014 16:31
Show Gist options
  • Save Achifaifa/630246e7db691b90ec1a to your computer and use it in GitHub Desktop.
Save Achifaifa/630246e7db691b90ec1a to your computer and use it in GitHub Desktop.
Simple file to automatically add commas to MySQL .csv dumps. Use python comas.py [filename]. CSV file must be in the same directory. Output in ./comas_out
#! /usr/bin/env python
import sys
if __name__=="__main__":
try:
path="./"+sys.argv[1]
except:
print "Use: python comas.py [filename]"
print "Wrong syntax or file not found"
try:
with open (path,"r") as infile:
with open ("./comas_out","w+") as outfile:
for line in infile:
if "0"<=line[0]<="9": outfile.write(line.strip()+",")
except:
print "File error"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment