Today, because beaubeau's lucky draw number was used as an SQL file, it was scared to get the ZIP file unzipped at first-29 CSV files, each file stores 1000 voucher IDs and numbers -_-!
Open each CSV file as before and create a separate SQL file. Each SQL statement contains 1000 insert statements, then copy and paste all SQL statements of 29 files into the same SQL file.
The structure of the CSV file is "ID, number", where ID is a 7-digit number and number is an 11-digit number. In this way, it is more convenient to use the regular expression for capturing. The regular expression used in the search/replace function of eclipse is "(\ D {7 }), (\ D {11}), the content of the text to be replaced is "insert into cards values ('$ 1',' $ 2', now ());". Use this method to replace the content in 29 CSV files.
AllCodeAs follows:Copy codeThe 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
Filters00000000'.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)
ProgramThe function is very simple, which is also the first step on the way to Python.
Rewrite this code when you have time, and add the regular expression replacement function.