ich moechte gern aus einer Datei (in Form einer Tabelle) die leeren Zellen mit '0' belegen.
Folgendes habe ich mir uebrlegt:
Code: Alles auswählen
inp = open('Suppl_Table_1.txt')
out = open('Suppl_Table_1_out1.txt','w')
for line in inp.readlines():
column = line.split()
if column[2] == ' ':
column[2] = '0'
if column[3] == ' ':
column[3] = '0'
if column[4] == ' ':
column[4] = '0'
if column[5] == ' ':
column[5] = '0'
if column[6] == ' ':
column[6] = '0'
if column[7] == ' ':
column[7] = '0'
if column[8] == ' ':
column[8] = '0'
if column[9] == ' ':
column[9] = '0'
if column[10] == ' ':
column[10] = '0'
out_line = '%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n' % (column[0],column[1],
column[2],column[3],
column[4],column[5],
column[6],column[7],
column[8],column[9],
column[10])
out.write(out_line)
inp.close()
out.close()
Wie ist ein leerer String definiert, doch schon so, oder?Traceback (most recent call last):
File "/home/cellnet/claudiak/bei/Analyse/NA_fuer_alle_leeren_Zellen.py", line 15, in <module>
if column[6] == ' ':
IndexError: list index out of range
leerer String = ' ' (Hochkomma Leerzeichen Hochkomma)
Kann mir jemand weiter helfen?