I have this working code:
S095 = 'S095'
E095 = 'E095'
DocLan = 'c:\DocLan.asc'
tempDocLan = open( DocLan, 'r+' )
for line in fileinput.input( DocLan ):
if fileinput.lineno() > 1:
LanNr = find_nth(line, "S095", 1), " - ",
line[find_nth(line, "S095", 1) + 5: find_nth(line, "S095", 1) + 14]
if LanNr > 10:
tempDocLan.write(line.replace(S095, E095))
else:
""
else:
tempDocLan.write(line)
tempDocLan.close()
I have tried to change the code to add a second write operation :
for line in fileinput.input(DocLan):
if fileinput.lineno() > 1 :
LanNr = find_nth(line, "S095", 1), " - ",
line[find_nth(line, "S095", 1) + 5: find_nth(line, "S095", 1) + 14]
if LanNr > 10:
tempDocLan.write(line.replace(S095, E095))
# error here
tempDocLan.write(line[0:50])
else:
""
else:
tempDocLan.write(line)
tempDocLan.close()
In the first write I replaced the text S095 for E095 In the second write I want to cut the text (with already E095), but it does not work.
I am using Python 2.7.
I'll give an example. I have a file with this content.
delete, S095/20140001,
delete, S095/20140002,
delete, S095/20140003,
delete, S095/20140004,
delete, S095/20140005,
delete, S095/20140006,
And I want to create this File.
E095/20140001,
E095/20140002,
E095/20140003,
E095/20140004,
E095/20140005,
E095/20140006,
Thanks for help.
Romeu Klug