access the name of my method inside it

Evan Klitzke evan at yelp.com
Thu Aug 2 01:22:53 EDT 2007


On 8/1/07, james_027 <cai.haibin at gmail.com> wrote:
> Hi,
>
> On Aug 1, 5:18 pm, Marc 'BlackJack' Rintsch <bj_... at gmx.net> wrote:
> > On Wed, 01 Aug 2007 09:06:42 +0000, james_027 wrote:
> > > for example I have this method
> >
> > > def my_method():
> > >     # do something
> >
> > >     # how do I get the name of this method which is my_method here?
> >
> > Why do you need this?  There are ways but those are not really good for
> > production code.
> >
>
> I am going to use this in Django. I am trying to implement a
> permission here, where in the database store the methods that the user
> are allowed to execute. for example if the method is def
> create_event(): the method will look for create_event in the database
> to see if it allow to be execute.
>
> Thanks.
> james

I would suggest instead setting an attribute on the function object
via a decorator, and then have your mod_python handler check for the
presence of that attribute on the function that is being called,
rather than doing a DB lookup.

-- 
Evan Klitzke <evan at yelp.com>



More information about the Python-list mailing list