# get_value¶

get_value(filename, token=None, skip_token=0, skip_line=0, skip_col=0, encoding='utf-8')

Get a value from a file using a delimiter and/or offsets.

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

Parameters: filename : str The name of 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 see http://docs.python.org/2/library/codecs.html#codec-base-classes value : float Value found AssertionError parameters badly set EOFError no value found

Examples

using a single token

>>> import openturns.coupling_tools as otct
>>> with open('results.out', 'w') as f:
...     count = f.write('Y1=2.0, Y2=-6.6E56')
>>> otct.get_value('results.out', token='Y1=')
2.0


using token and skip_tokens

>>> with open('results.out', 'w') as f:
...     count = f.write('Y1=2.6 Y1=6.0 # temperature 2')
>>> otct.get_value('results.out', token='Y1=', skip_token=1)
6.0


using column & line

>>> with open('results.out', 'w') as f:
...     count = f.write('1.1 1.2 1.3 1.4')
>>> otct.get_value(filename='results.out', skip_col=2)
1.3