io module¶
read_tsv¶
- read_tsv(path: pathlib.Path, as_dict: Literal[False], **kwargs) Generator[List[str], None, None][source]¶
- read_tsv(path: pathlib.Path, as_dict: Literal[True], columns: List[str], **kwargs) Generator[Dict[str, str], None, None]
Read a plain-text or gzip compressed TSV table.
When as_dict is False, return each row as a list using
csv.reader().When as_dict is True, return each row as a dict mapping from the column name to the corresponding value using
csv.DictReader. columns will be used as the column names. If columns is omitted, the first row will be treated as the column names.Additional arguments
kwargsare passed to the underlying function.Examples
>>> tsv_pth = Path('inheritance_gene_table.tsv.gz') >>> reader = read_tsv(tsv_pth) >>> header = next(reader); header ['gene', 'disease', 'modes_of_inheritance'] >>> row = next(reader); row[-1] 'autosomal recessive, autosomal dominant'
>>> reader = read_tsv(tsv_pth, as_dict=True) >>> row_d = next(reader) >>> row_d['gene'] 'SDHA'
read_csv¶
- read_csv(path, *, dialect='excel', as_dict=False, columns=None, **kwargs)¶
Read a plain-text or gzip compressed CSV table.
See
read_tsv()for its usage.
read_lines¶
- read_lines(path)[source]¶
Read a plain-text or gzip compressed text per line.
- Parameters
path (pathlib.Path) –
- Return type
List[str]