Set a flag on the function or a global?
Ethan Furman
ethan at stoneleaf.us
Mon Jun 15 20:21:43 EDT 2015
On 06/15/2015 05:07 PM, Chris Angelico wrote:
> On Tue, Jun 16, 2015 at 9:57 AM, Steven D'Aprano wrote:
>> I have two ideas for this, a module-level global, or a flag set on the
>> function object itself. Remember that the usual way of using this will be
>> "from module import edir", there are two obvious ways to set the global:
>>
>> import module
>> module.dunders = False
>>
>> # -or-
>>
>> edir.__globals__['dunders'] = False
>>
>>
>> Alternatively, I can use a flag set on the function object itself:
>>
>> edir.dunders = False
>>
>
> For most situations, the last one is extremely surprising - attributes
> on functions aren't normally meant to be changed by outside callers,
I find this viewpoint surprising, since function attributes are fairly rare.
> it always feels wrong (they belong to the function itself).
This seems silly -- a function is just another instance of some class.
--
~Ethan~
More information about the Python-list
mailing list