Today because of the lottery numbers provided to Beaubeau to do SQL files, initially received ZIP file decompression compression was frightened--29 CSV files, each file saved 1000 lottery ID and number-_-!
As before, open each CSV file to do a separate SQL file, with 1000 inserts in each SQL, and then copy and paste all the SQL statements from the 29 files into the same total SQL file.
The structure in the CSV file is the structure of "Id,number", where the ID is 7 digits and number is 11 digits. It is convenient to use regular-style capture, and the regular formula used in Eclipse's Find/Replace function is "(\d{7}), (\d{11})", and the textual content of the replacement is "INSERT into cards VALUES (' $ ', ' $ '), Now ()); ". Use this method to replace the contents of the 29 CSV files.
All codes are as follows:
The code is as follows:
Import sys, OS
def readFile (filename):
File=open (filename, "R")
S=file.read (). Strip ()
File.close ()
return s
def writefile (filename, files):
Content=[]
For f in Files:
Print "Reading file '%s '"% f
S=readfile (f)
Print "Read file '%s ' completed"% f
Content.append (s)
Print "Writing file '%s '"% filename
File=open (filename, "w")
File.write ("\n/*-----This is a seperating line.-----*/\n". Join (content))
File.close ()
Print "Write file '%s ' completed"% filename
filters=['. txt ']
FULLPATH=OS.GETCWD ();
Print "Opening directory: '%s '"% FullPath
Sys.path.append (FullPath)
Files = Os.listdir (FullPath)
Files =[f for f in Files if Os.path.splitext (f) [1].lower () in filters]
WriteFile ("Beaunet_be_card.sql", files)
The function of the program is simple, and this is my first step on the path of Python.
Rewrite this code when you have time, and join the regular replacement function