[Tutor] Working with output of a subprocess

Dave Angel d at davea.name
Sat Jan 12 00:09:46 CET 2013


On 01/11/2013 05:29 PM, 3n2 Solutions wrote:
> Hello,
>
> Need some help with working with a text file.
> Is it possible to get the values associated with each of the parameter in
> the below text file format? For example:

There are no intrinsic parameters and values in a text file.  it's free
form characters.  On the other hand, if the format is a standard one,
there may be a library that parses it for you.  For example, configparser.

On the other hand, if you have a spec, you can write a parser.  Your
example doesn't look like any standard, so we'd be guessing.

>
> 1. How can I check what the Min and Max values are?

Assuming that the value of Min is "

 "val           :     15"

then you could get it by scanning through the file looking for the line that begins with the string "Min "

       ...
       if line.startswith("Min "):
             result = line[4:]

> 2. How to check the second column value associated with "epoch2"?

Use the same approach to find the value of epoch2:  Then split based on
the colon, and then on whitespace.
    parts = line.split(":")
    subparts = parts[1].split()


> Your help is greatly appreciated. I'm using Python 2.7 on Windows7.
>
>
>
> Examining file: 5521W2310000.txt
>
> Duration                 :      0h : 59m
> First meas : week   :  86     :   1721
> Last  meas : week   :  89     :   1721
>
> Min val           :     15
> Max val         :     18
> 3D             :   3600  100.0%
>
> summary         Total  Missed    Rate
> epoch1                :        1378       0       0\1000
> epoch2                :        2154       1       0\1000
>
>
> Thanks,
> Tim
>
>



-- 

DaveA



More information about the Tutor mailing list