1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
|
#!/usr/bin/env python
# -*-coding: utf-8 -*
entetes = [
'Name',
'Description',
'DataType',
'Format',
'From',
'To'
]
t = []
valeurs = []
w = ""
i = 0
debut = ""
for line in enumerate(lines):
s = lines[i]
if s.startswith("<FixedColumn>") :
debut = "OK"
if debut == "OK":
if s.startswith("<Name>") :
s = s.replace("<Name>", "")
s = s.replace("</Name>","")
t.append(s)
if s.startswith("<Description>") :
s = s.replace("<Description>", "")
s = s.replace("</Description>","")
t.append(s)
if s.startswith("<AlphaNumeric/>") :
s = s.replace("<AlphaNumeric/>", "AlphaNumeric")
verifFormat = "no"
t.append(s)
w = "NaN"
t.append(w)
if s.startswith("<Numeric>") :
s = s.replace("<Numeric>", "Numeric")
verifFormat = "no"
t.append(s)
w = "NaN"
t.append(w)
if s.startswith("<Date>") :
s = s.replace("<Date>", "Date")
t.append(s)
verifFormat = "yes"
if s.startswith("<Format>") and verifFormat == "yes":
s = s.replace("<Format>", "")
s = s.replace("</Format>","")
verifFormat = "no"
t.append(s)
if s.startswith("<From>") :
s = s.replace("<From>", "")
s = s.replace("</From>","")
t.append(s)
if s.startswith("<To>") :
s = s.replace("<To>", "")
s = s.replace("</To>","")
t.append(s)
i += 1
valeurs.append(t)
print (t)
f = open('monFichier.csv', 'w')
ligneEntete = ";".join(entetes) + "\n"
f.write(ligneEntete)
for valeur in valeurs:
ligne = ";".join(valeur) + "\n"
f.write(ligne)
f.close() |
Partager