A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-August/017251.html below:

[Python-Dev] Customizing the binding of attributes

[Python-Dev] Customizing the binding of attributes [Python-Dev] Customizing the binding of attributesGuido van Rossum guido@python.org
Thu, 23 Aug 2001 15:23:42 -0400
> In Python 2.2, is it possible to customize the binding
> of class attributes, to emulate the normal behaviour
> of methods (function -> unbound method -> bound method)?
> 
> I think I have read something about this, but I can't
> find it anymore.

I'm not sure what you are asking about, but let me give an example.
You can write an auxiliary class that "describes" an instance
attribute.  Instances of this "descriptor" class are stored in a class
dict.  The descriptor class implements a method __get__ which is
called in two situations:

(a) when a class attribute is retrieved, <attr>.__get__(None, <class>)
    is called; this can return an unbound method

(b) when an instance attribute is retrieved, <attr>.__get__(<inst>, <class)
    is called; this can return a bound method

Does this help?

--Guido van Rossum (home page: http://www.python.org/~guido/)



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4