2

How can I print the inside of a lambda function?

For example, from the following lambda expression:

lambda a, b: a / b

I want to receive:

a / b

Or from this expression:

lambda a, b: math.pow(a, b)

To receive:

pow(a, b)
RnadomG
  • 145
  • 1
  • 9
  • 2
    A lambda is a function. You're asking to print the source code of the function in nicely human readable format. You can't just do that – sshashank124 Jan 06 '20 at 09:40
  • Does this answer your question? [How can I get the source code of a Python function?](https://stackoverflow.com/questions/427453/how-can-i-get-the-source-code-of-a-python-function) – Linh Nguyen Jan 06 '20 at 09:41
  • Another good question would be why would you want to do this? maybe there is a better way to do what you want. – Chris Doyle Jan 06 '20 at 09:42
  • 3
    Why/how should `lambda a, b: math.pow(a, b)` result in just `pow(a, b)`…? – deceze Jan 06 '20 at 09:42
  • 1
    I don't think the tagged question has a direct answer for the question. It only has explained how to get the source code. using the same inspect library you can apply a regular expression to get what is needed. I dont see a reason to downvote or close this question – Marlon Abeykoon Jan 06 '20 at 09:47
  • 2
    It is already answered : https://stackoverflow.com/questions/334851/print-the-code-which-defined-a-lambda-function – divyang4481 Jan 06 '20 at 09:48
  • lambda itself is a just a function without name being declared, you can set the name with `function_name = lambda function` – Linh Nguyen Jan 06 '20 at 09:55

0 Answers0