pyrokinetics.file_utils.ReadableFromFile#
- class pyrokinetics.file_utils.ReadableFromFile[source]#
Bases:
objectBase class that adds the following functions to a class:
from_file: A classmethod that allows a instance of the readable class to be created from a file path.supported_file_types: Returns a list of all registered file types that can be used to instantiate the readable class.
It also adds the following private objects:
_factory: AFileReaderFactorythat returns ‘readable’ subclasses._register: A function used to register ‘reader’ classes with the readable, allowing those classes to be used when reading files from disc.
- __init__()#
Methods
__init__()from_file(path[, file_type])Read a file from disk, returning an instance of this class.
Returns a list of all registered file types.
- classmethod from_file(path, file_type=None, **kwargs)[source]#
Read a file from disk, returning an instance of this class.
- Parameters:
path (
PathLike) – Location of the file on disk.file_type (
Optional[str]) – String specifying the type of file. If unset, the file type will be inferred automatically. Specifying the file type may improve performance.**kwargs – Keyword arguments forwarded to the file reader.
- Raises:
ValueError – If
pathdoes not refer to a valid file.RuntimeError – If
file_typeis unset, and it is not possible to infer the file type automatically.
- classmethod supported_file_types()[source]#
Returns a list of all registered file types. These file types are readable by
from_file().