grapa.parse.parser_generic.FileParserGeneric
- class grapa.parse.parser_generic.FileParserGeneric
Bases:
objectMethods to parse a file, organized with header key-values, then multicolumn data
- __init__()
Methods
cast_curves(graph)cast Curves as child class if specified by attr 'curve'
read(graph, attributes[, fileContent, ...])Reads the file as a column-organized data file, with some headers lines at the beginning.
read_lines(filename, file_content, ...)Read a file, returns the lines as a list of str
- classmethod read(graph: Graph, attributes: dict, fileContent=None, ifReplaceCommaByPoint=False, **kwargs)
Reads the file as a column-organized data file, with some headers lines at the beginning.
- Parameters:
graph – the graph to put the data in
attributes –
provided when intantiating the Graph object. Special keyword:
_singlecurve: parse all data into a single Curve object
fileContent – if content to parse is given as a string, not from file read
ifReplaceCommaByPoint – if numbers are formatted with ‘,’ instead of ‘.’
kwargs –
the following keywords are handled:
delimiter: if provided, assumed the values is the text delimiter.
delimiterHeaders: same as delimiter, but only for the headers section
lstrip: if provided, a lstrip function is applied to each line when parsing the file. Values: None (lstrip(None)), True, or ‘# ‘ etc.
- classmethod read_lines(filename: str, file_content, replace_comma_dots: bool, lstriparg) Tuple[List[str], str]
Read a file, returns the lines as a list of str
- Parameters:
filename – str of the filename to open
file_content – None, or alternative content (if so, filename is not open).
replace_comma_dots – bool
lstriparg – if not None, .lstrip(*lstriparg) on lines. [str | None] | None]
- Returns:
a list of str, one str per line in file