iprPy.tools package

Module contents

aslist(term)

Create list representation of term. Treats a str, unicode term as a single item.

Parameters

term (any) – Term to convert into a list, if needed.

Returns

All items in term as a list

Return type

list of any

dynamic_import(module_name, ignorelist=None)

Dynamically imports classes stored in submodules and makes them directly accessible by style name within the returned loaded dictionary.

Parameters
  • module_name (str) – The name of the module to start from

  • ignorelist (list, optional) – A list of submodules that should be excluded from the import.

Returns

  • loaded (dict) – Contains the derived classes that were successfully loaded and accessible by style name (root submodule).

  • failed (dict) – Contains the raised error messages for each class that failed to load.

filltemplate(template, variable, s_delimiter, e_delimiter)

Takes a template and fills in values for delimited template variables.

Parameters
  • template (string or file-like object) – The template file or file content to fill in.

  • variable (dict) – Dictionary with keys defining the delimited template variable terms, and values the values to replace the variable terms with.

  • s_delimiter (str) – The leading delimiter for identifying the template variable terms.

  • e_delimiter (str) – The trailing delimiter for identifying the template variable terms.

Returns

The template with all delimited variable terms replaced with their corresponding defined values from variable.

Return type

str

Raises
  • KeyError – If delimited term found in template that has no value in variable.

  • ValueError – If parsing of s_delimiter, e_delimiter pairs fails.

iaslist(term)

Iterate over items in term as if term was a list. Treats a str, unicode term as a single item.

Parameters

term (any) – Term to iterate over.

Yields

any – Items in the list representation of term.

read_calc_file(filename, filedict)

Utility function for reading the contents of required calculation files, whether the calculation was called using the script or through an iprPy Calculation object.

Parameters
  • filename (str) – The name of the file to read/get content for.

  • filedict (dict) – Should be empty if calculation is called by script, and should have all file names and contents if calculation is called through iprPy.

Returns

The file’s contents, either by reading the file or from filedict

Return type

str

screen_input(prompt='')

Replacement input function that is compatible with the mingw terminal.

Parameters

prompt (str, optional) – The screen prompt to use for asking for the input.

Returns

The user input.

Return type

str