which comes from the input string using getattr (i know it can be unsafe, but it's a learning test server on my courses), but not all functions take 2 arguments, is there a way to truncate the arguments i'm passing dynamically to comply with the amount the function requires?
can you give an example in your case, what kind of functions do you have, and when does your getattr fail
operands = (args.operand_1, args.operand_2) return getattr(operator, function)(*operands)
and when will this fail, for example?
for cos or exp, for example TypeError: cos() takes exactly one argument (2 given) maybe i just should wrap it in a try except TypeError and do return getattr(operator, function)(operands[0])
you could read the signature
Обсуждают сегодня