get_regex¶
- get_regex(filename, patterns, encoding='utf-8')¶
Get values from a file using regex.
- Parameters
- filenamestr
The name of the file to parse
- patternslist of str
Regex patterns that will permit to get the values see https://docs.python.org/2/library/re.html for available patterns The value to be searched must be surrounded by parenthesis.
- encodingstr
File encoding see http://docs.python.org/2/library/codecs.html#codec-base-classes
- Returns
- resultslist of float
Each value corresponds to each pattern. If nothing has been found, the corresponding value is set to None.
- Raises
- AssertionError
parameters badly set
- EOFError
no value found
Examples
>>> import openturns.coupling_tools as ct >>> # write an output file >>> with open('results.out', 'w') as f: ... count = f.write('@E=-9.5E3') >>> # parse file with regex >>> ct.get_regex('results.out', patterns=[r'@E=(\R)']) [-9500.0]