bw2parameters.interpreter#

Classes#

Module Contents#

class bw2parameters.interpreter.Interpreter(*args, **kwargs)[source]#

Bases: asteval.Interpreter

_raise_missing_name()[source]#
add_symbols(symbols)[source]#

Adds symbols to the symtable.

eval(expr, *args, known_symbols=None, raise_errors=True, **kwargs)[source]#
get_symbols(text)[source]#

Parses an expression and returns all symbols.

classmethod get_unit_dimensionality(unit_name=None)[source]#
get_unknown_symbols(text, known_symbols=None, ignore_symtable=False, no_pint_units=None)[source]#

Parses an expression and returns all symbols which are neither in the symtable nor passed via known_symbols.

classmethod is_numeric(value)[source]#
classmethod is_quantity(value)[source]#
classmethod is_quantity_from_same_registry(value)[source]#
classmethod parameter_list_to_dict(param_list)[source]#
remove_symbols(symbols)[source]#

Removes symbols from the symtable.

classmethod set_amount_and_unit(obj, quantity, to_unit=None)[source]#
user_defined_symbols()[source]#
BUILTIN_SYMBOLS[source]#
class bw2parameters.interpreter.PintInterpreter(*args, units=None, **kwargs)[source]#

Bases: Interpreter

_raise_proper_pint_exception()[source]#

Make sure that pint exceptions are correctly raised during evaluation

add_symbols(symbols)[source]#

Adds symbols to symtable while making sure that pint Quantities are from same registry as self.ureg (otherwise self.eval will fail).

eval(expr, *args, known_symbols=None, **kwargs)[source]#
get_pint_symbols(text, known_symbols=None, ignore_symtable=True)[source]#

Parses an expression and returns all symbols which can be interpreted as pint units.

classmethod get_unit_dimensionality(unit_name=None)[source]#
get_unknown_symbols(text, known_symbols=None, ignore_symtable=False, include_pint_units=False, no_pint_units=None)[source]#

Parses the given expression and returns a list of symbols, which are neither contained in the symtable, nor in known_symbols, nor can be interpreted as pint units

classmethod is_numeric(value)[source]#
classmethod is_quantity(value)[source]#
classmethod is_quantity_from_same_registry(value)[source]#
classmethod parameter_list_to_dict(param_list)[source]#

Takes a list of parameter objects and returns a dict where keys are the parameter names and values are the interpreted pint.Quantities (or float where no unit is defined).

parse(text)[source]#
classmethod set_amount_and_unit(obj, quantity=None, to_unit=None)[source]#

Takes an arbitrary object and tries to set it’s amount and unit fields. amount field is the magnitude of the pint.Quantity after conversion to to_unit. If no to_unit is given, the quantity’s own unit will be used. If the input is not a pint.Quantity then obj[‘unit’] will be used. If no quantity is given, then obj[‘amount’] and obj[‘unit’] are used.