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
|
#-*- coding: utf-8 -*-
#ouvrire le fichier entree
fichier_e = open("D:\\fichier_e.txt")
#lire toutes les lignes et les stocker dans un tableau
lignes_e = fichier_e.readlines()
#fermer le fichier
fichier_e.close()
#on va declarer un tableau qui contiendera (start_date, article, Store)
tab_start_date = []
tab_article = []
tab_store = []
#on va extraire les donnes (les separer) dans un tableau de tableau
#de la forme tab_data[i] = [start_date, article, Store n°, n°]
tab_data = map(lambda x:[x[0:9],x[9:16],x[16:22],x[21:-1]], lignes_e)
print tab_data[0]
#imprimer les lignes du fichier 1
lignes_f1 = []
for data in tab_data:
_ligne = data[3] + " " + data[2] + "\n"
lignes_f1.append(_ligne)
fichier_f1 =open("D:\\fichier_1.txt", 'w')
fichier_f1.writelines(lignes_f1)
fichier_f1.close()
#deuxieme fichier
#(Store_id = 1, Start_date=20080409, Start_date+6jours = 20080415, article = 1111111)
lignes_f2 = []
for data in tab_data:
_ligne = data[3] + data[0].strip() + str(int(data[0])+6)+ data[1] +"\n"
lignes_f2.append(_ligne)
fichier_f2 =open("D:\\fichier_2.txt", 'w')
fichier_f2.writelines(lignes_f2)
fichier_f2.close() |
Partager