pyrolite.util.general

class pyrolite.util.general.Timewith(name='')[source]
property elapsed
checkpoint(name='')[source]
pyrolite.util.general.temp_path(suffix='')[source]

Return the path of a temporary directory.

pyrolite.util.general.flatten_dict(d, climb=False, safemode=False)[source]

Flattens a nested dictionary containing only string keys.

This will work for dictionaries which don’t have two equivalent keys at the same level. If you’re worried about this, use safemode=True.

Partially taken from https://stackoverflow.com/a/6043835.

Parameters
  • climb (bool, False) – Whether to keep trunk or leaf-values, for items with the same key.

  • safemode (bool, True) – Whether to keep all keys as a tuple index, to avoid issues with conflicts.

Returns

Flattened dictionary.

Return type

dict

pyrolite.util.general.swap_item(startlist: list, pull: object, push: object)[source]

Swap a specified item in a list for another.

Parameters
  • startlist (list) – List to replace item within.

  • pull – Item to replace in the list.

  • push – Item to add into the list.

Return type

list

pyrolite.util.general.copy_file(src, dst, ext=None, permissions=None)[source]

Copy a file from one place to another. Uses the full filepath including name.

Parameters
  • src (str | pathlib.Path) – Source filepath.

  • dst (str | pathlib.Path) – Destination filepath or directory.

  • ext (str, None) – Optional file extension specification.

pyrolite.util.general.remove_tempdir(directory)[source]

Remove a specific directory, contained files and sub-directories.

Parameters

directory (str, Path) – Path to directory.