Home > other >  Help me to the content of an array to generate a SQL file
Help me to the content of an array to generate a SQL file

Time:11-24

Beginners python, can put the string content through a variety of want to split the last CSV format, I have the original documents, code, and finally to generate CSV upload to the website so now need to put the contents of this CSV into SQL format, but, I will not, excuse me, can somebody help me write this last array to generate SQL code?
Data and code in a network backup link: https://pan.baidu.com/s/1E9YHEum093RqyPli8bEJqQ extraction code: bk46
The code below:

 

# import ast
# import re
# with open (" f:/amf/out/out TXT ", "r", encoding="utf-8") as f: # Settings file object

# import pandas as pd
The import CSV

Def findkey (txtall, word1 word2) :
# txt1=[]
# txt2=[]
Txt1=txtall. Split (word1)
# print (txt1)
# print (" this is the definition of def TXT [1] ")
# print (txt1 [1])
Txt2=txt1 [1]. The split (word2)
Return txt2 [0]

# dayDesc_stuff=[]

Def remove_duplicates (l) :
Return sorted (set (l), key=l.i ndex)

Path='f:/amf/out/mini. TXT'
='f # path:/amf/out/all. TXT'
With the open (path, "r") as f: # Settings file object
STR=f.r ead (#) may be random to the operation of the file
# print (STR)
# x=STR. Split (" {")
# STR=STR. Replace ("} ", "{")
# print (STR)
X=STR. Split (" {' dayNo ") # {' dayNo '
# print (x)
Length_x=len (x)
# print (length_x)
PyCode=[]
DayNo=[]
DayDesc=[]
PackDesc=[]
Name=[]
FreqCode=[]
GroupName=[]
ExPreItem=[]

Stuff=[]

For I in range (len (x)) :
Result_packDesc='packDesc in x [I]
Result_pyCode='pyCode in x [I]
Result_dayDesc='dayDesc in x [I]
Result_name='name' in x [I]
Result_freqCode='freqCode in x [I]
Result_groupName='groupName in x [I]
Result_exPreItem='exPreItem in x [I]
If (result_packDesc==True) and (result_pyCode==True) and (result_dayDesc==True) and (result_name==True) and (result_freqCode==True) and (result_groupName==True) and (result_exPreItem==True) :
Stuff. Append (x [I])


# # # below is pycode value
For I in range (len (stuff)) :
# print (I)
PyCode_stuff=findkey (stuff [I], "' pyCode ':'," "'")
# print (" this is stuff [i_pyCode] ")
# print (stuff [I])
PyCode. Append (pyCode_stuff)
# print (" here is the stuff [pyCode] ")
# print (f "pyCode {[I]}={pyCode [I]}.")
# below is dayDesc value

# print (stuff)
# # # below is dayDesc value
For I in range (len (stuff)) :
# print (I)
DayDesc_stuff=findkey (stuff [I], "' dayDesc ':'," "'")
# print (" this is stuff [i_dayDesc] ")
# print (stuff [I])
DayDesc. Append (dayDesc_stuff)
# print (" here is the stuff [dayDesc] ")
# print (f "dayDesc {[I]}={dayDesc [I]}.")

# # # below is dayNo value
For I in range (len (stuff)) :
# print (I)
DayNo_stuff=findkey (stuff [I], ":",, "")
# print (" this is stuff [i_dayDesc] ")
# print (stuff [I])
DayNo. Append (dayNo_stuff)
# print (" here is the stuff [dayDesc] ")
# print (f "dayNo {[I]}={dayNo [I]}.")

For I in range (len (stuff)) :
# print (I)
PackDesc_stuff=findkey (stuff [I], "' packDesc:",, "")
# print (" this is stuff [i_dayDesc] ")
# print (stuff [I])
PackDesc. Append (packDesc_stuff)
# print (" here is the stuff [dayDesc] ")
# # print (f "packDesc {[I]}={packDesc [I]}.")

For I in range (len (stuff)) :
# print (I)
FreqCode_stuff=findkey (stuff [I], "' freqCode ':'," "'")
# print (" this is stuff [i_dayDesc] ")
# print (stuff [I])
FreqCode. Append (freqCode_stuff)
# print (" here is the stuff [dayDesc] ")
# print (f "freqCode {[I]}={freqCode [I]}.")

For I in range (len (stuff)) :
# print (I)
GroupName_stuff=findkey (stuff [I], "' groupName ':'," "'")
# print (" this is stuff [i_dayDesc] ")
# print (stuff [I])
GroupName. Append (groupName_stuff)
# print (" here is the stuff [dayDesc] ")
# # print (f "groupName {[I]}={groupName [I]}.")

For I in range (len (stuff)) :
# print (I)
Name_stuff=findkey (stuff [I], "' name ':'," "'")
# print (" this is stuff [i_dayDesc] ")
# print (stuff [I])
The name, append (name_stuff)
# print (" here is the stuff [dayDesc] ")
# print (f "name {I}={name} [I].")

Con=", "
BigString=[]
For I in range (len (stuff)) :
BigString. Append (dayNo [I] + con + dayDesc [I] + con + packDesc [I] + con + name + con + [I] freqCode [I] + con + groupName [I] + con + pyCode [I])
# print (bigString [I])

SimpleString=remove_duplicates (bigString)
# cutString=simpleString. The split () ", "
Simple_day=[]
Simple_dayNo=[]
Simple_dayDesc=[]
Simple_packDesc=[]
Simple_name=[]
Simple_freqCode=[]
Simple_groupName=[]
Simple_pyCode=[]

For I in range (len (simpleString) :
Print (f "simpleString {I}={simpleString [I]}.")
Simple_day. Append (simpleString [I]. The split (", "))
Print (simple_day [I])
Simple_dayNo. Append (simple_day [I] [0])
Simple_dayDesc. Append (simple_day [I] [1])
Simple_packDesc. Append (simple_day [I] [2])
Simple_name. Append (simple_day [I] [3])
Simple_freqCode. Append (simple_day [I] [4])
Simple_groupName. Append (simple_day [I] [5])
Simple_pyCode. Append (simple_day [I] [6])

# print (simple_pyCode [I])




# # # to write an array into the CSV

# any more groups of list
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related