0

The functions Assurance_WL(age, i=0.04) and Annuity_WL(age, i=0.04) are defined. The functions have attributes Assurance_WL.latex and Annuity_WL.latex which return the latex representation of these functions.

Given a string such as:
EL0 = '100000*Assurance_WL(55) - 2000*Annuity_WL(55, 0.065) + (1500 + 3000)/0.95'
I can use the eval function to compute the result.

However, to display these input expressions, I am trying to manipulate the above string to produce something like: '100000*Assurance_WL.latex - 2000*Annuity_WL.latex + (1500 + 3000)/0.95' The problem is that I need to remove the parenthesis from the function call which can be of varying lengths. I'm not sure what is the best way to achieve this.

  • Functions have a `__name__` property, tried that? – Random Davis Aug 19 '22 at 18:31
  • Does this answer your question? [How to input a regex in string.replace?](https://stackoverflow.com/questions/5658369/how-to-input-a-regex-in-string-replace) – max Aug 19 '22 at 18:32
  • Show us the parsing code you have written so far. I imagine it would use the AST module. https://docs.python.org/3/library/ast.html#ast.parse – J_H Aug 19 '22 at 18:35

0 Answers0