processing input from multiple files

Christopher Steele christopher.steele at uea.ac.uk
Thu Oct 14 10:44:41 EDT 2010


The issue is that I need to be able to both, split the names of the files so
that I can extract the relevant times, and open each individual file and
process each line individually. Once I have achieved this I need to append
the sorted files onto one another in one long file so that I can pass them
into a verification package. I've tried changing the name to textline and I
get the same result - the sorted files overwrite one another.
The data are actually meteorological observations and I need to manipulate
them in order to test the performance of a model. The 333 denotes that cloud
observations are going to follow - something that is not always reported at
stations.

I hope this has helped

Chris


On Thu, Oct 14, 2010 at 3:16 PM, John Posner <jjposner at optimum.net> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101014/853fd969/attachment.html>


More information about the Python-list mailing list