getting the current function

Jonathan Gardner at
Tue Sep 11 01:05:38 CEST 2007

On Sep 7, 9:19 am, Gary Robinson <gary... at> wrote:
> > This all seems a bit too complicated. Are you sure you want to do
> > this? Maybe you need to step back and rethink your problem.
> In version 2.1 Python added the ability to add function attributes -- see the justifications. A counter probably isn't one of them, I just used that as a quick example of using thisfunc().
> I've just never liked the fact that you have to name the function when accessing those attributes from within the function. And I thought there might be other uses for something like thisfunc().

If I had a scenario where I needed a function that would change its
behavior based on its attributes I would use an object instead. If I
really, really needed it to behave like a function, then I would
override __call__.

Using a function's attributes to modify its behavior seems like using
a singleton or a module variable to modify the behavior of functions.
I would avoid it if I wanted to write code that someone else
(including myself) may want to use one day. Otherwise, it would be
hard to keep different bits of code separate from one another.

More information about the Python-list mailing list