Function attributes

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Wed Feb 10 13:58:02 EST 2010


On Wed, 10 Feb 2010 17:23:36 +0000, MRAB wrote:

> Stephen Hansen wrote:
>> On Wed, Feb 10, 2010 at 6:36 AM, Steven D'Aprano
>> <steve at remove-this-cybersource.com.au
>> <mailto:steve at remove-this-cybersource.com.au>> wrote:
>> 
>>     On Wed, 10 Feb 2010 05:59:41 -0800, Muhammad Alkarouri wrote:
>>      > What is the simplest way to access the attributes of a function
>>      > from inside it, other than using its explicit name? In a
>>      > function like f
>> 
>>     Not built-in.

[...]

> Does this mean that Python needs, say, __function__ (and perhaps also
> __module__)?

Python already has __module__, except that it is spelled:

import __main__


As for __function__, perhaps, but a solution I would be satisfied with 
would be to make it optional. Most functions are not recursive, and do 
not attach attributes to themselves. For the few that do need to refer to 
themselves, it would be sufficient to call a decorator to get the 
behaviour needed. I thought I had come up with such a thing, once before, 
but I can't find it now :(


-- 
Steven



More information about the Python-list mailing list