nesting class definitions?

Thomas Wouters thomas at xs4all.net
Mon Jan 31 08:44:12 EST 2000


On Sun, Jan 30, 2000 at 06:27:41PM +0000, Aahz Maruch wrote:

> Yup.  But try this one on for size:

> def SpamGen ( foo ):
> 	class Spam:
> 		bar = foo
> class Viking:
> 	def __init__(self, foo):
> 		self.spamClass = SpamGen(foo)

Er, correct me if i'm wrong, but shouldn't this generate a NameError (asside
from SpamGen returning None, of course) ? Or did you intend to show that
this is very clear and very useful code, but impossible at the moment ?

> (Yeah, this is essentially meta-class stuff, which I know you know
> about, but I think presenting it slightly differently like this will
> make sense to more people.  It certainly makes more sense to me --
> metaclasses usually make my head hurt.  ;-)

Ssshhht, not so loudly, I've been wrestling with sendmail all last week...
my head still hurts enough, thank you very much ;) I still don't quite
understand Metaclasses, just as I dont quite understand closures - I think I
know what they are, but if they really are what I think they are, they are
really simple concepts, and I can't figure out why everyone is making such a
big fuss about them. Perhaps it is because I've never _needed_ those
concepts, I've always (in my entire 1 year experience with python) been able
to do everything I want using the simple and elegant namespace & scoping
rules used by Python.

The absolute greatest thing about Python, for me, is that everything I care
about (almost everything there is) is immediately clear, incredibly
intuitive, and comes naturally when writing Python. The only problem with
that is that I don't quite trust it, still. I'll be happily writing away,
and suddenly notice that I try to do something that might not work (force of
habbit, I still write C and Perl more often than Python) and fire up the
interpreter to test it out. I have yet to find something that didn't behave
as I expected ;)

Please, whatever else changes, whatever crufty C++ habbits get added,
whatever Java-lookalike constructs are thought up, whatever new truly
pythonic features are inserted, dont change that aspect of Python.

Loving-(Python)-ly y'rs,
-- 
Thomas Wouters <thomas at xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!




More information about the Python-list mailing list