processing input from multiple files

John Posner jjposner at optimum.net
Thu Oct 14 10:16:28 EDT 2010


On 10/14/2010 6:08 AM, Christopher Steele wrote:
> Hi
>
> I've been trying to decode a series of observations from multiple files
> (each file is a different time) and put each type of observation into
> their own separate file. The script runs successfully for one file but
> whenever I try it for more they just overwrite each other.

fileinput.input() iterates over *lines* not entire *files*. So take a 
look at this location in the code:

   for file  in fileinput.input(obs):
       data=file[:file.find(' 333 ')]

Did you mean your iteration variable to be "file", implying that it will 
hold an entire file of input data?

If you meant the iteration variable to be named "textline" instead of 
"file", is it guaranteed that string '  333  ' will occur in every such 
text line?


-John



More information about the Python-list mailing list