materials module

Material database.

materials.absolute_path(filename)

Get full path.

Parameters

filename (str) – the file name to use

Returns

str – the absolute path

materials.get_value(data, element)

Get value of nested dictionary. If data element is itself a list of length one, the element of the list is returned.

Parameters
  • data (dict) – the data

  • key (str) – the key to get

Returns

int or float or list or dict – element value of the dict

materials.load_material(materialname)

Read material file and convert it to a Python object.

Parameters

materialname (str) – the material name to load

Returns

list or dict – the content of the material

materials.main()

Main function.

materials.print_dict(data_dict, print_keys=True, prespaces=0)

Print one dimensional dict data.

Parameters
  • data_dict (dict) – the dict data to print

  • print_keys (bool) – print the keys (default value = True)

  • prespaces (int) – number of spaces as prefix (default value = 0)

materials.print_list(data_list)

Print list.

Parameters

data_list (list) – the list to print

materials.print_material(data)

Print material data (Python object).

Parameters

data (str or list or dict) – the material data

materials.print_quantity(quantity, prespaces=0)

Print quantity.

Parameters
  • quantity (int or float or list) – the quantity to print. Either a number or a list of two elements, the first the magnitude and the second the unit.

  • prespaces (int) – number of spaces as prefix (default value = 0)

materials.read_dir(directory, exclude=None, fullpath=False, extension=True)

Read all files in directory as list.

Parameters
  • directory (str) – the directory to read

  • exclude (list or None) – file names that should be excluded from the list (default value = None)

  • fullpath (bool) – get full path (default value = False)

  • extension (bool) – include file extension (default value = True)

Returns

list – the list of files in the directory

materials.read_file(filename)

Read file as string.

Parameters

filename (str) – the name of the file to read

Returns

str – the content of the file

materials.read_material(materialname, fullpath=True)

Read material file as string.

Parameters
  • materialname (str) – the name of the material to read

  • fullpath (bool) – use full path (default value = True)

Returns

str – the content of the material

Raises
  • OSError – raises os exception

  • IOError – raises io exception

materials.search_keys(data, keys)

Search for json keys in string data.

Parameters
  • data (str) – the data to search in

  • keys (str or list or None) – the key to search for

Results

dict – the key value pair matching the given keys in the data