carabiner.io package
Submodules
carabiner.io.utils module
Utilities for IO.
- carabiner.io.utils.count_lines(filename: TextIOWrapper | str, progress: bool = True, *args, **kwargs) int[source]
Count lines in a file, optionally gzipped.
Provides a progress bar by default.
- Parameters:
filename (str) – Path of file to read. Optionally GZIP compressed.
progress (bool) – Whether to display a progress bar. Default True.
- Returns:
Number of lines in input file.
- Return type:
int
- carabiner.io.utils.get_lines(filename: TextIOWrapper | str, lines: int | Sequence[int] | None = None, progress: bool = True, outfile: TextIOWrapper | None = None, *args, **kwargs) TextIOWrapper | StringIO[source]
Extract lines from a file, optionally GZIPped, by line number.
Provides a progress bar by default.
- Parameters:
filename (str or file-like) – Path of file to read, or a file-like object. Optionally GZIP compressed.
lines (list of int, optional) – Rows to read. If None (default), read all rows.
progress (bool) – Whether to display a progress bar. Default True.
outfile (file-like, optional) – Open file handle for output.
- Returns:
File-like object containing lines from the input file.
- Return type:
TextIOWrapper or StringIO