Set a flag on the function or a global?
Michael Torrie
torriem at gmail.com
Tue Jun 16 09:44:57 EDT 2015
On 06/15/2015 06:20 PM, Ben Finney wrote:
> I'm surprised by your assertion. To my mind, outside callers get simple
> and direct access to the attribute, whereas the code of the function
> itself does not have such easy access; unlike ‘self’ for the current
> instance of a class, there's no obvious name to use for referring to the
> function object within the function object's own code.
Of course it has access, and it's obvious and easy as well:
def foo():
foo.flag = True
The only thing I'm not sure of is a clean way to test for the
attribute's existence. The __init__.py of a package, or the
initialization code of the module could preset the attribute, though.
More information about the Python-list
mailing list