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!
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!
Put the following into a script file:
#!/bin/python
import inspect
def f(x):
return x * x
print inspect.getsource(f)