[Tutor] Filter question
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Tue Apr 13 15:31:48 EDT 2004
> (molecular dynamics output to visualizer input). I have set up the
> following filter, but it is not working. I don't receive an error
> message just a blank prompt at shell. Here is the code. I am trying to
> filter out any line the begins with I. I am using python 2.3.3. Thanks.
>
> Ara
>
> def filterFile(lmps, out):
> inp = open("lmps","r")
> outp = open("out","w")
> while 1:
> text = inp.readline()
> if line == "":
> break
> if line[0] == 'I':
> continue
> outp.write(line)
>
> inp.close()
> outp.close()
Hi Ara,
There's a bug in the file opening code:
###
def filterFile(lmps, out):
inp = open("lmps","r")
outp = open("out","w")
...
###
The code, as written, is trying to open up a file that's literally named
'Imps' for reading. It's also trying to open up a file that is literally
called 'out'.
Hope this helps!
More information about the Tutor
mailing list