Smalltalk and Python
Andrew Dalke
dalke at acm.org
Thu Dec 14 23:49:23 EST 2000
Greg Ewing wrote:
>the TADS (Text Adventure Development System)
>lets you declare objects with multiple
>classes, e.g.
>
> bed: Furniture, Surface, Scenery
> ...
...
>This is really just syntactic sugar,
...
>To mention something vaguely Python-relevant:
>if Python had a convenient syntax for declaring
>singletons, it could be a pretty good language for
>Interactive Fiction...
One packet of syntactic sugar, coming up!
def make_a(*classes):
class make_a:
pass
make_a.__bases__ = tuple(classes)
return make_a()
class Furniture:
def comfy(self): return 1
class Surface:
def genus(self): return 0 # Imagine a spherical cow...
class Scenery:
def description(self): return "boring"
>>> bed = make_a(Furniture, Surface, Scenery)
>>> bed
<__main__.make_a instance at 0x120330628>
>>> bed.description()
'boring'
>>> bed.genus()
0
>>> bed.comfy()
1
>>>
Andrew
dalke at acm.org
More information about the Python-list
mailing list