Parsers¶
Classes for simple file processing
Keyword parser¶
-
class
drewtils.parsers.KeywordParser(filePath, keys, separators=None, eof='')¶ Class for parsing a file for chunks separated by various keywords.
Parameters: - filePath (str) – Object to be read. Any object with
readandclosemethods - keys (Iterable) – List of keywords/phrases that will indicate the start of a chunk
- separators (Iterable or None) – List of additional phrases that can separate two chunks.
If not given, will default to empty line
'\n'. - eof (str) – String to indicate the end of the file
-
line¶ str – Most recently read line
-
parse()¶ Parse the file and return a list of keyword blocks.
Returns: List of key word argument chunks. Return type: list
-
yieldChunks()¶ Return each chunk of text as a generator.
Yields: list – The next chunk in the file.
- filePath (str) – Object to be read. Any object with
PatternReader¶
-
class
drewtils.parsers.PatternReader(filePath)¶ Class that can read over a file looking for patterns.
Parameters: filePath (str) – path to the file that is to be read -
line¶ str – Most recently read line
-
match¶ regular expression match or None – Match from the most recently read line
-