0

I can do a program that read its own code using f=open(sys.argv[0]) and then parse it, but, exist a simple way to do something like this?

>>> def f(x): return x*x
...
>>> print(definition_of(f))
"def f(x): return x*x"

Thanks!

diego
  • 109
  • 7
  • Hi! yes, this is a duplicate... I'm very sorry for that, i did a search with no result, but, i didn't with the correct words. Thanks! (no proble if a moderator delete it) – diego Sep 20 '14 at 22:11

1 Answers1

0

Put the following into a script file:

#!/bin/python

import inspect

def f(x):
  return x * x

print inspect.getsource(f)
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358