Getting method name from within the class method

yellowalienbaby at gmail.com yellowalienbaby at gmail.com
Thu Oct 19 00:30:07 CEST 2006


Gabriel Genellina wrote:
> At Wednesday 18/10/2006 18:59, Mitko Haralanov wrote:
>
> > > >>> class test(object):
> > > ...  def a_method(self,this,that):
> > > ...   print self.a_method.__name__
> >
> >Doing the above will obviously work!
> >
> >However, I don't want to have to use the name of the function in the
> >print statement (the ".a_method." part). Imagine having about 100 of
> >the above print statements in the function and then you change the name
> >of the function. I want all 100 of the print statements to work without
> >having to change every one of them to reflect the new function name.
>
> Use the inspect module.
>
>
> --
> Gabriel Genellina
> Softlab SRL
>
>

I'm sure the OP has good reasons, and I dont want to be arguing with
anyone, but I am curious. If I found myself in a similar situation I
wouldn't try to include code in whatever I'm  writing that simply aids
my writing of the code; it's irrelevant to the application and in my
mind, shouldn't be there. its probably only a tiny bit of extra
resource etc.. included into the app's use of resources and hence not
really so important, but I would feel happier with my end code if I
hadn't done such a thing.




More information about the Python-list mailing list