[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: OT : Sempre Script



Forwardo in lista... Scusami Lorenzo! :)

Il 17 gennaio 2012 11:35, Lorenzo Sutton <lorenzofsutton@gmail.com> ha scritto:
> Allora lo script in python non funzionerà in generale.

Prova questo. Utilizzo: "python nome_script nome_file_in nome_file_out"
-------------------------------
#!/usr/bin/python

import sys

filename_in = sys.argv[1]
filename_out = sys.argv[2]

fout = open(filename_out, 'w')

for line in open(filename_in, 'r'):
   first_field = test_string[0:2]
   second_field = test_string[2:17]
   third_field = test_string[17:38]
   fourth_field = test_string[38:46]
   fifth_field = test_string[46:]

   length_third = len(third_field)

   new_third_field = str(int(third_field)).ljust(length_third)

   field_list = (first_field, second_field, new_third_field,
                 fourth_field, fifth_field)

   fout.write(''.join(field_list))
   fout.write('\n')

fout.close()
-------------------------------

L'ho scritto così più per chiarezza che altro... :)

Ciao,
Simone


Reply to: