pyarts.utils

This module contains convenience functions for any purposes.

class pyarts.utils.TempFileHandler(prefix='pyarts', suffix='.tmp', dir=None)[source]

Context manager for creating and deleting temporary files.

This class is a context manager that creates a temporary file and deletes it when the context is exited. The file is automatically removed if an exception occurs.

Parameters:
  • prefix (str) – Optional prefix for the temporary file name.

  • suffix (str) – Optional suffix for the temporary file name.

  • dir (str) – Optional directory for the temporary file.

__init__(prefix='pyarts', suffix='.tmp', dir=None)[source]
pyarts.utils.deprecated(func=None, new_name=None, message=None)[source]

Decorator which can be used to mark functions as deprecated.

Examples

Calling foo() will raise a DeprecationWarning.

>>> @deprecated
... def deprecated_function():
...     pass

Display message with additional information:

>>> @deprecated(message='Additional information message.')
... def deprecated_function():
...     pass
pyarts.utils.path_append(dirname, path='PATH')[source]

Append a directory to environment path variable.

Append entries to colon-separated variables (e.g. the system path). If the entry is already in the list, it is moved to the end. A path variable is set, if not existing at function call.

Parameters:
  • dirname (str) – Directory to add to the path.

  • path (str) – Name of the path variable to append to. Defaults to the system path ‘PATH’.

pyarts.utils.path_prepend(dirname, path='PATH')[source]

Prepend a directory to environment path variable.

Append entries to colon-separated variables (e.g. the system path). If the entry is already in the list, it is moved to the end. A path variable is set, if not existing at function call.

Parameters:
  • dirname (str) – Directory to add to the path.

  • path (str) – Name of the path variable to append to. Defaults to the system path ‘PATH’.

pyarts.utils.path_remove(dirname, path='PATH')[source]

Remove a directory from environment path variable.

Remove entries from colon-separated variables (e.g. the system path). If the path variable is not set, nothing is done.

Parameters:
  • dirname (str) – Directory to add to the path.

  • path (str) – Name of the path variable to append to. Defaults to the system path ‘PATH’.

pyarts.utils.unique(seq)[source]

Remove duplicates from list whilst keeping the original order

Notes

If you do not care about keeping the order, use this code: >>>> list(set([0, 5, 1, 2, 0, 3, 1,])) [0, 1, 2, 3, 5]

This code is taken from https://stackoverflow.com/a/480227.

Parameters:

seq – A sequence (list, etc.) of elements.

Returns:

A list with unique items with original order.

Examples

>>>> unique([0, 5, 1, 2, 0, 3, 1,])