Prothon Prototypes vs Python Classes

Andrew Bennetts andrew-pythonlist at puzzling.org
Sat Mar 27 23:04:17 EST 2004


On Sun, Mar 28, 2004 at 03:37:25AM +0000, Joe Mason wrote:
[...]
> 
> Ed Suominen just posted a situation where classes and instances need to
> be treated separately.  He has a class, "AutoText", with various
> subclasses (which I'll call "AutoA", "AutoB", etc. because I forget the
> details).  He wants to notice whenever somebody creates a subclass of
> AutoText and add it to a list so that he can have an AutoAll function
> which creates just one instance of each.  (Or something like that.)
> 
[...]
> In Python, the easiest way to do this is with metaclasses, which is a
> really advanced topic.  In Prothon, it's simple to "notice" when a
> subclass is created, because __init__ gets called!  So you just say:

Actually, in Python, it's even easier than that:

>>> class C(object): pass
... 
>>> class D(C): pass
... 
>>> C.__subclasses__()
[<class '__main__.D'>]

-Andrew.





More information about the Python-list mailing list