A RetroSearch Logo

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

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2006-March/063147.html below:

[Python-Dev] Class decorators

[Python-Dev] Class decoratorsRaymond Hettinger raymond.hettinger at verizon.net
Thu Mar 30 12:56:23 CEST 2006
[Jack Diederich]
>> Classes have a unique property in that they are the easiest way to make
>> little namespaces in python.

[Greg Ewing]
> For a while now, I've been wondering whether it would
> be worth having a construct purely for creating little
> namespaces, instead of abusing a class for this.

FWIW, I do not consider it an abuse to use a class to create a small namespace. 
Essentially that is what it is for -- it matters not whether the class has no 
methods.

What I've been wanting is the ability to easily define functions directly into 
an existing namespace:

    class A:
        pass

    def A.mymethod(x):
        return x+1

The latter definition is equivalent to:

    A.mymethod = lambda(x): x+1

This ability to inject function definitions into an existing namespace is the 
one missing piece to enable clean use of Protocol OO techniques:

    a = Object.copy()
    b = a.copy()
    def b.f(x):
        return x+1
    c = b.copy()
    def c.f(x):
        return x+2


Raymond




More information about the Python-Dev mailing list

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