get_value

get_value(filename, token=None, skip_token=0, skip_line=0, skip_col=0, encoding='ascii')

Get one result from a file using token and/or various offsets.

This function is optimized to be rather fast and takes low memory on human readable file.

Parameters:

filename : str, the file that will be parsed

token : str, a regex that will be searched.

The value right after the token is returned. Default: None (no token searched)

skip_token : int, the number of tokens that will be skipped before getting

the value. If set to != 0, the corresponding token parameter must not be equal to None. If skip_tokens < 0: count tokens backward from the end of the file. Default: 0: no token skipped

skip_line : int, number of lines skipped from the token found.

If corresponding token equal None, skip from the beginning of the file. If corresponding token != None, skip from the token. If skip_line < 0: count lines backward from the token or from the end of the file. Be careful: a last empty line is taken into account too. Default: 0: no line skipped

skip_col : int, number of columns skipped from the token found.

If corresponding token = None, skip words from the beginning of the line. If corresponding token != None, skip words from the token. If skip_col < 0: count col backward from the end of the line or from the token. Default: 0: no column skipped

encoding : str, file encoding

Returns:

value : float

Raises:

AssertionError

parameters badly set

EOFError

no value found

Examples

simple token (results.out = ‘ @Y1=2.6, Y2= -6.6E56’)

>>> # Y = coupling_tools.get_value(filename='results.out',
>>> #                        token='@Y1=',
>>> #                        )
>>> # Y = 2.6

using token ans skip_tokens (results.out = '@Y1=5.9 @Y1=2.6 # temperature 2’)

>>> # Y = coupling_tools.get_value(filename='results.out',
>>> #                        token='@Y1=',
>>> #                        skip_token=1,
>>> #                        )
>>> # Y = 2.6

using column & line (results.out = ‘ 2.6 3.5 6.8 9.0 3.6 7.5 6.9 9.8 ‘) >>> # Y = coupling_tools.get_value(filename=’results.out’, >>> # skip_line=1, >>> # skip_col=-2, >>> # ) >>> # Y = 6.9

mix it (results.out = ‘ 2.6 Y1=3.5 Y1=6.8 9.0 temperatures: 88.8 99.9 # ‘)

>>> # Y = coupling_tools.get_value(filename='results.out',
>>> #                        token='Y1=',
>>> #                        skip_token=1,
>>> #                        skip_line=0,
>>> #                        skip_col=1,
>>> #                        )
>>> # Y = 9.0