CLParse¶
- class bapsflib._hdf.maps.controls.parsers.CLParse(command_list: str | Iterable[str])¶
Bases:
object
Class for parsing RE from a command list. (A command list is a list of strings where each string is a set of commands sent to a control device to define that control device’s state.)
- Parameters:
command_list (list of strings) – the command list for a control device
Methods Summary
apply_patterns
(patterns)Applies a the REs defined in
patterns
to parse the command list.try_patterns
(patterns)Prints to the results of applying the REs in patterns to the command list.
Methods Documentation
- apply_patterns(patterns: str | Iterable[str])¶
Applies a the REs defined in
patterns
to parse the command list.- Parameters:
patterns (str or list of strings) – list or raw strings defining REs for parsing the command list
- Returns:
(bool, dict)
- Example:
>>> # define a command list >>> cl = ['VOLT 20.0', 'VOLT 25.0', 'VOLT 30.0'] >>> >>> # define clparse object >>> clparse = CLParse(cl) >>> >>> # apply patterns >>> patterns = (r'(?P<FREQ>(FREQ\s)' >>> + r'(?P<VAL>(\d+\.\d*|\.\d+|\d+)))') >>> results = clparse.apply_patterns(patterns) >>> results[0] True >>> results[1] {'VOLT': {'cl str': ('VOLT 20.0', 'VOLT 25.0', 'VOLT 30.0'), 'command list': (20.0, 25.0, 30.0), 're pattern': re.compile(pattern, re.UNICODE), 'dtype': numpy.float64}}