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/2002-November/029893.html below:

[Python-Dev] metaclass insanity

[Python-Dev] metaclass insanityGreg Ewing greg@cosc.canterbury.ac.nz
Tue, 05 Nov 2002 14:04:43 +1300 (NZDT)
Alex Martelli <aleaxit@yahoo.com>:

> I could define that "class Inner" in any place at all, but since it's
> only meant to be used in this one spot, why not define it right here?

Putting it inside the function means the class definition
is executed every time the function is called, which is
rather needlessly inefficient.

You could get most of the namespace benefit by putting
it one level further out, i.e.

  class Foo:

    class Iterator:
      ...

    def __iter__(self):
      return self.Iterator(self)

The iterator class would then be known from outside
as Foo.Iterator, which is nicely descriptive and makes
it fairly obvious what it's for.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg@cosc.canterbury.ac.nz	   +--------------------------------------+



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