[Python-ideas] Functions and Unbound methods

Steven D'Aprano steve at pearwood.info
Fri Feb 22 07:00:47 CET 2013


On 21/02/13 13:11, robert2682 wrote:
>
>
> Hi,
>
> I'm new; greetings all!
>
> I'm not sure if this is a bug or feature, but it confused me so I thought
> I'd raise the issue.

Not a bug, but a feature, and in fact a fundamental way that Python works.

The def statement creates functions. Always, without exception. So when you
define a method in a class, you're actually defining a function. It doesn't
get converted to a method until later, when it is retrieved via attribute
access from the class or instance. You can google on "descriptor protocol"
to learn more about it, although that is considered fairly advanced.

This mailing list is actually intended for discussing new ideas and future
changes to the Python language, standard library, and compiler, not for
generic questions like this. For general questions, you should subscribe
to the "python-list at python.org" mailing list, or "tutor@" if you are a
beginner.

If you repeat your question there, someone will reply with a more detailed
response and some suggestions for your code.


-- 
Steven



More information about the Python-ideas mailing list