On 12.01.2013 00:29, 3n2 Solutions wrote:
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:

1. How can I check what the Min and Max values are?
2. How to check the second column value associated with "epoch2"?




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


Alan's approach, writing a parser is right, just what I might want to add.

Just by looking at the general structure of the file:

For example the line:
"epoch1                :        1378       0       0\1000"
its like:

command/parameter TAB TAB ":" value TAB value TAB value"\"secondValue

Having a deeper look:
1) go line by line and check if the line starts with a searched value, like said 2) use a split to break up the structure of that line if its a command you want to get the values from, diving it to command, value pair using ":" as a split character (for the epoch line)

Now you could split the value part result[2] = result[2].split('\t')
by "\t" tabulator sign and access the subvalues of that.

So the structure will be something like, after the 2nd split:
['epoch1', [1378, 0, '0\1000']]

If you encounter that there are tabs inside the command result, you can use str.rstrip('\t') to cut off tabs.

To avoid that the timestamp gets broken up into two parts, use str.split(':', 1) (only one split of that line) or similar.

Hope that helps.

Jan
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to