pyiron_base.storage.filedata.FileLoader

pyiron_base.storage.filedata.FileLoader#

class pyiron_base.storage.filedata.FileLoader[source]#

Bases: object

Class for loading different file types.

__init__()#

Methods

__init__()

load(file_type, file, *args, **kwargs)

Load a file of a specific type.

register(file_type, load_callable)

Register a load function for a specific file type.

Attributes

default_assumed_file_type

load(file_type: str, file: str | IO, *args, **kwargs) Any[source]#

Load a file of a specific type.

Parameters:
  • file_type (str) – File extension indicating the type of the file.

  • file (str or file-like object) – Path to the file or file object.

Returns:

Object containing the loaded data.

Return type:

Any

Raises:

IOError – If the file could not be loaded.

classmethod register(file_type: str, load_callable: Callable) None[source]#

Register a load function for a specific file type.

Parameters:
  • file_type (str) – File extension to be registered, e.g. ‘.txt’, ‘.csv’

  • load_callable (callable) – Function accepting a file or file-handle, returning an appropriate object for this file type.