Home

SanPy <jhmsmits@gmail.com> wrote:

> So basically, my question is: is there a way to access a function from
> within itself without using its name?
>
Not really, no. Python is executing a code block, it has no idea which
function referenced that code block.

You can get the current code object quite easily (inspect.currentframe
().f_code), but the reference from function to code is one way: a single
code object could be used by multiple functions.

You can get the source code though, so if you are desperate enough you
could try parsing the source code to extract the docstring:

print inspect.getsource(inspect.currentframe())

Use the name of the function, that's the best way.

previous
next

Re: Problem using boost::bind() with template functions having arguments
Problem from complex string messing up
Re: How to find out if the interpreter is a debug build?
Re: Making a small change to a large XML document
Sorting two arrays with one call to sort()?
Mam Marzenie
Pajacyk
Krwinka
Mimo Wszystko
Dzieci Niczyje