[Tutor] Parsing txt file
Dave Angel
davea at davea.name
Thu Aug 21 00:09:16 CEST 2014
Dima Kulik <dexternet89 at mail.ru> Wrote in message:
Please post in text mode. The html mode you used can cause
multiple problems.
Please specify your Python version and os version in any new
thread.It sometimes makes a big difference in the
solution.
Your primary problem is that you don't close the files.
But you should start by writing a specification. I'm not sure what
you mean by all stings. I'd assume you mean all lines. But that's
not what the code does. The code is looking at every word of
every line. Perhaps you mean the first word of the input
file.
You say the output is clear, by which I'm guessing you mean the
output file is empty. Since there could
be many causes for that,
I'd suggest adding appropriate print statements to see what
happened.
I'd also suggest removing the call to readlines. It doesn't change
the result, and causes several problems. One is that input _
file is not a File, but a list. It becomes impossible to close
it, and if the file is large it wastes memory.
--
DaveA
More information about the Tutor
mailing list