print fileinput, and screen ?
Shagshag13
shagshag13 at yahoo.fr
Mon Jul 22 15:51:06 EDT 2002
hello,
i've tried fileinput to do inplace modification like :
---
countDone = 0
lineI = 0
lineBuffer = []
for line in fileinput.input(FILE_TO_PROCESS,inplace=1, backup='.sav'):
if line.find('</') != 0:
lineBuffer.append(line)
else:
if len(lineBuffer) > 0:
lineBuffer[len(lineBuffer) - 1] = lineBuffer[len(lineBuffer) - 1][:-1] + line
countDone += 1
for l in lineBuffer:
print l.strip()
lineBuffer = []
lineI += 1
if lineBuffer != []:
for l in lineBuffer:
print l.strip()
print " Correcting [%s] lines" % countDone # how to be sure this one will never be in FILE_TO_PROCESS ??? but redirect to screen ?
---
and as i do some other printing to stdout (print script times, counts, etc.) i'm wondering if that couldn't conflict with "print"
for fileinput ?
is there a correct way to do it (print in fileinput, and distinct print to screen) ?
thanks in advance,
s13.
More information about the Python-list
mailing list