Arbitrary dunder attributes (was Re: odd difference calling function from class or instance variable)
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Wed Aug 13 09:12:16 EDT 2014
Chris Angelico wrote:
> The bound method object stores a reference to the original object (the
> thing that becomes the first argument to the target function) in
> __self__ (and the function in __func__). ISTM this ought to be _self
> (and _func), as it's intended to be private;
Why do you say they are intended to be private? Is that documented
somewhere, or do you mean that if you designed the system, *you* would have
intended them to be private? :-)
> is it really something
> that has language-level significance on par with __lt__ and so on?
To be honest, I didn't even know about __self__, but I understood __func__
to be public. And yes, it should be public: being able to introspect a
method and find the function it came from is a good thing, and sometimes
useful.
--
Steven
More information about the Python-list
mailing list