inPmos = False
inFile = sys.stdin
fileList = inFile.readlines()
for line in fileList:
line = line.rstrip()
# Remove PMOS definitions - typically two lines. Screwed if only
one and last inst.
if inPmos:
inPmos = False
continue
if 'pmos4_highv' in line:
inPmos = True
continue
jr
A generator certainly would be handy:
def read_lines(inFile):
fg = iter(inFile)
for line in fg:
if "pmos4_highv" in line:
fg.next()
else:
yield line
lines = """a
b
c
d
pmos4_highv
no no!
e
f
g""".split("\n")
for line in read_lines(lines):
print line
Diez
Just be aware that the "fb.next()" line can raise an StopIteration
exception that would otherwise be caught by the for loop. If you have
any resources that need to be cleaned up, try...finally is you friend.
--
Felipe.
Actually I did that on purpose - as the StopIteration would simply end
the generator. Any clean-up - well, if that was the scope of the
generator on could add it of course, but I'd do that on the same level
the file has been opened.
Regards,
Diez