Reading parts of a log file to an array in Python -


i have previous experience python, has been while i'm bit rusty. i'm trying figure out how extract parts of log file array.

below sample (3 lines, 14 numerical entries each) of log file:

       -3.440208377846361e-002 -3.640975490509869e-002   3.77129385321508       7.937315452622962e+040  1.067031475475027e-015  6.626932578094536e+039  2.637269012342617e+034  6.626906205404414e+039  2.008451522885638e+025   2426438437.29153        13424548.8207020       1013967360829.11        364214556916.216        1100.16964475087        -3.442345778664616e-002 -3.643241462492964e-002   3.77129983957511       1.588956060345964e+041  2.136069984437443e-015  6.626924938142817e+039  1.056889619379146e+035  6.626819249180878e+039  8.048900417930891e+025   2426441623.69160        13424487.5716696       2029898474163.94        729111075239.864        1100.17676257806        -3.447047146128363e-002 -3.644149740258100e-002   3.77129262754527       2.781765670453510e+041  3.739591232686748e-015  6.626924955173501e+039  3.239268437345529e+035  6.626601028329767e+039  2.466913157350972e+026   2426441630.05298        13424487.4034776       3553717920905.67        1276445706704.12        1100.17678094667 

which continues on hundreds of lines (depends on situation). have set save 601 lines per data run, number cannot seem trusted because have noticed number of lines vary 595-605. think have first determine number of lines used code.

i have used following code test reading log file (similar answer iterating on file using python):

with open("output.log", 'r') f:      line in f:           print line 

and works fine (indenting may wrong in above block).

my issue how extract 3rd number each line , put array? more straightforward if log files named letters numbers (i.e. 3rd element perhaps "m_3.7729385321508", because search "m_" in each line , extract 15 characters following underscore array; see http://www.wellho.net/solutions/python-log-file-analysis-short-python-example.html), that's not case.

when read log file, formatted list containing strings. each string corresponds 1 line of log file.

any appreciated!

if it's going third number on each line, can accomplished str.split().

>>> line in s.splitlines():         print line.split()[2]   3.77129385321508 3.77129983957511 3.77129262754527 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -