Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #72089

Re: confused about the different built-in functions in Python

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From Marko Rauhamaa <marko@pacujo.net>
Newsgroups comp.lang.python
Subject Re: confused about the different built-in functions in Python
Date Mon, 26 May 2014 23:58:37 +0300
Organization A noiseless patient Spider
Lines 38
Message-ID <87egzgfe9u.fsf@elektro.pacujo.net> (permalink)
References <648e6136a80.00000651codemonkey@inbox.com> <6C977160E42.0000036Ccodemonkey@inbox.com> <mailman.10353.1401130279.18130.python-list@python.org> <87r43gfjqy.fsf@elektro.pacujo.net> <mailman.10356.1401133664.18130.python-list@python.org> <87ioosffh3.fsf@elektro.pacujo.net>
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
Injection-Info mx05.eternal-september.org; posting-host="ff5cf27ef3d5b31f034d3b72bdc27a41"; logging-data="20210"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1//VtKSMv4xGB23PvR39iHI"
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux)
Cancel-Lock sha1:5Mo6wk6MBqizwDJWuYRkszhemvo= sha1:yrSMFMq5hRlm4V2Km1wmzMWYoIw=
Xref csiph.com comp.lang.python:72089

Show key headers only | View raw


Marko Rauhamaa <marko@pacujo.net>:

> Christian Heimes <christian@python.org>:
>
>> Python creates a new bound method object every time. A bound method
>> object is a callable object that keeps a strong reference to the
>> function, class and object. The bound method object adds the object as
>> first argument to the function (aka 'self').
>
> I stand corrected. I had thought the trampoline ("bound method
> object") was created once and for all.

Sure enough. The principle is explicitly specified in <URL:
https://docs.python.org/3.2/reference/datamodel.html#index-46>.

Thus:

   >>> class X:
   ...   def f(self):
   ...     print("Hello")
   ... 
   >>> x = X()
   >>> x.f()
   Hello
   >>> def f(): print("Meh")
   ... 
   >>> x.f = f
   >>> x.f()
   Meh
   >>> delattr(x, "f")
   >>> x.f()
   Hello

IOW, you can override a method with setattr() but you cannot delete a
method with delattr().


Marko

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: confused about the different built-in functions in Python Terry Reedy <tjreedy@udel.edu> - 2014-05-26 14:51 -0400
  Re: confused about the different built-in functions in Python Marko Rauhamaa <marko@pacujo.net> - 2014-05-26 22:00 +0300
    Re: confused about the different built-in functions in Python Christian Heimes <christian@python.org> - 2014-05-26 21:47 +0200
      Re: confused about the different built-in functions in Python Marko Rauhamaa <marko@pacujo.net> - 2014-05-26 23:32 +0300
        Re: confused about the different built-in functions in Python Marko Rauhamaa <marko@pacujo.net> - 2014-05-26 23:58 +0300
          Re: confused about the different built-in functions in Python Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-05-27 11:14 +1200
          Re: confused about the different built-in functions in Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-05-27 01:21 +0000
        Re: confused about the different built-in functions in Python Terry Reedy <tjreedy@udel.edu> - 2014-05-26 22:00 -0400

csiph-web