Re: Why doc call `__init__` as a method rather than function?

Liste des GroupesRevenir à cl python 
Sujet : Re: Why doc call `__init__` as a method rather than function?
De : ram (at) *nospam* zedat.fu-berlin.de (Stefan Ram)
Groupes : comp.lang.python
Date : 15. Sep 2023, 13:42:13
Autres entêtes
Organisation : Stefan Ram
Message-ID : <methods-20230915133118@ram.dialup.fu-berlin.de>
References : 1
scruel tao <scruelt@hotmail.com> writes:
The book PYTHON CRASH COURSE

  I suggest to read "The Python Language Reference" (the "PRL")
  by "Guido van Rossum and the Python development team" for
  terminological questions.

I wonder how can I call `__init__` as?

  The PRL usually refers to the value of an object's __init__
  attribute as a "method".

  A method is a function that can be associated with a object
  in a special way.

  When a function is retrieved from the attribute of an instance,
  an instance method object is created (PRL 3.11.1 3.2)
  and becomes the value of the expression for the attribute.
  This usually applies to "__init__". Methods are based on functions.
  The method's __func__ attribute is the original function.
  The instance is the method's __self__ attribute.

  But when you look at values of __init__, you can find all
  kinds of things, like "wrappers":

|>>> object.__init__
|<slot wrapper '__init__' of 'object' objects>

|>>> object().__init__
|<method-wrapper '__init__' of object object at 0x0...>

  .



Date Sujet#  Auteur
15 Sep 23 o Re: Why doc call `__init__` as a method rather than function?1Stefan Ram

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal