The utilities module

A module which contains various utility methods for handling strings and floats.

utilities.is_number(s)[source]

Test a string to see if it is a number.

Parameters

s (string) – string which is being tested

Returns

True if s is a number, and False otherwise

Return type

boolean

Note

This method allows “d” and “D” as an exponent (i.e. for Fortran style numbers).

utilities.my_input()[source]

Select appropriate input function depending on whether python2 or python3 is being used.

utilities.my_map(fct, lst)[source]

Systematically applies a function to a list of items. This deals with the python3 behaviour of map which returns a map object rather than a list.

Parameters
  • fct (function) – the function to be applied to each element of a list

  • lst (list) – the list to which is applied the function

utilities.sparse_print(filename, mat)[source]

Print a sparse matrix (for debug purposes only):

Parameters
  • filename (string) – name of the file in which to print the matrix

  • mat (numpy array) – the matrix to be printed

utilities.to_float(s)[source]

Convert a string to a float.

Parameters

s (string) – string which will be converted to a float

Returns

the corresponding float

Return type

float

Note

This method allows “d” and “D” as an exponent (i.e. for Fortran style numbers).

utilities.trim(s)[source]

Return a string with comments (starting with “#”) removed.

Parameters

s (string) – the string for which we would like to remove comments.

Returns

the string without comments

Return type

string