filefinder.matches#
Matches management.
Functions
|
Get sorted list of groups indices corresponding to key. |
Classes
|
Match extract from a filename. |
|
Scan an input file and store the results. |
- class Match(group, match, idx)#
Match extract from a filename.
- Parameters:
- group#
Group used to get this match.
- match_str#
String matched in the filename.
- start#
Start index of match in the filename.
- end#
End index of match in the filename.
- match_parsed#
Parsed value. None if parsing was not successful.
- get_match(parse=True)#
Get match string or value.
- Parameters:
parse (bool) – If True (default), and the parsing was successful, return the parsed value instead of the matched string.
- Raises:
ValueError – Could not parse the match.:
- Return type:
- class Matches(match, groups)#
Scan an input file and store the results.
- Parameters:
- classmethod from_filename(filename, pattern, groups)#
Find matches for a given filename.
- Parameters:
- Returns:
matches – A
Matches
object, or None if the filename did not match.- Raises:
IndexError – Not as many matches as groups. Maybe one of the group regex contains an additional (unwanted) capturing group ?
- Return type:
Matches | None
- get_matches(key, keep_discard=False)#
Get Match objects corresponding to key.
- Parameters:
- Returns:
List of Match corresponding to the key.
- Return type:
- get_value(key, parse=True, keep_discard=False)#
Get matched value corresponding to key.
Return a single value. If multiple groups correspond to
key
, the value of the first one to appear in the pattern is returned.- Parameters:
- Raises:
KeyError – No group with no ‘discard’ option was found.:
- Return type:
- get_values(key, parse=True, keep_discard=False)#
Get matched values corresponding to key.
Return a list of values, even if only one group is selected.
- groups#
Groups used.
- matches: list[filefinder.matches.Match]#
Matches for a single filename.
- get_groups_indices(groups, key)#
Get sorted list of groups indices corresponding to key.
Key can be an integer index, or a string of a group name. Since multiple groups can share the same name, multiple indices can be returned (sorted).
- Raises:
IndexError – No group found corresponding to the key:
TypeError – Key is not int or str:
- Parameters:
groups (list[filefinder.group.Group]) –
- Return type: