0

Here is my MWE (which looks stupid):

def somefunc(a0,a1,b1,a2,b2):
    first = 'a0'
    rest = ['+a{}+b{}'.format(i,i) for i in range(1, int((len(locals())-1) / 2)
    for element in rest:
        first+=element
    return exec(first)

Basically I want to create an expression without having to type it in. So I use list comprehension with strings and then I execute.

However if I try somefunct(1,1,1,1,1) I get absolutely nothing..

Euler_Salter
  • 3,271
  • 8
  • 33
  • 74
  • 1
    Assuming you fixed the unbalanced brackets in `rest`, and you replaced `exec` with `eval`, you might find that your `first` string did not end up as you intended. You should at least print it out and see what it says. – khelwood Nov 16 '17 at 11:48
  • Why is it a duplicate of that one? i don't even know what eval does – Euler_Salter Nov 16 '17 at 11:59
  • @Euler_Salter So go read the answers to that question and find out – khelwood Nov 16 '17 at 12:06

0 Answers0