base
A module containing the base class for all writers and readers.
Summary
Classes:
A base class for all readers. |
|
A base class for all writers. |
Reference
- class BaseReader(filename: str | list[str])[source]
Bases:
object
A base class for all readers.
This class can be used as a base class for all Readers implemented in the PQAnalysis package. It provides the functionality to read from a file or multiple files. If the filename is a string, the file is read from. The basic idea is just to ease the handling of multiple files and to provide a common interface for all readers. The actual reading is done in the methods of the subclasses. This wrapper only sets the filename/filenames and checks if the file/files exist. Furthermore, a boolean is set to indicate if the reader reads from a single file or multiple files.
Initializes the BaseReader with the given filename.
- Parameters:
filename (str or list of str) – The name of the file to read from or a list of filenames to read from.
- Raises:
FileNotFoundError – If the given file does not exist.
- logger = <CustomLogger PQAnalysis.BaseReader (INFO)>
- class BaseWriter(
- filename: str | None = None,
- mode: str | FileWritingMode = 'w',
Bases:
object
A base class for all writers.
This class can be used as a base class for all writers. It provides the functionality to write to a file or stdout. Meaning, if the filename is None, the output is printed to stdout. Otherwise, the output is written to the given file. The mode of the file can be either ‘w’ for write or ‘a’ for append. If the mode is ‘w’ and the file already exists, a ValueError is raised. If the mode is ‘a’ and the file does not exist, it is created. If the mode is ‘o’ and the file already exists, it is overwritten.
Attention
Please be aware that after the initialization of the BaseWriter, the file is not opened yet. To open the file, the open() method has to be called. To close the file, the close() method has to be called. After calling the open() method of a file that already exists, the mode is automatically set to ‘a’. This means that for all subsequent calls of the open() method, the mode is ‘a’ and not ‘w’. This is to prevent overwriting the file by accident.
- Parameters:
filename (str or None, optional) – The name of the file to write to. If None, the output is printed to stdout.
mode (FileWritingMode or str, optional) – The mode of the file. Use one of the modes in FileWritingMode or ‘w’ for write, ‘a’ for append or ‘o’ for overwrite. The default is ‘w’.
- Raises:
ValueError – If the given mode is not in .
ValueError – If the given filename already exists and the mode is ‘w’.
- logger = <CustomLogger PQAnalysis.BaseWriter (INFO)>
- property mode: FileWritingMode
The mode of the file.
The setter checks if the given mode is in BaseWriter.modes. Furthermore, if the mode is ‘w’ and the file already exists, a ValueError is raised. If the mode is ‘a’ and the file does not exist, it is created. If the mode is ‘o’ and the file already exists, it is overwritten.
- Type: