[Tutor] __init__ for class instantiation?
Zak Arntson
zak@harlekin-maus.com
Fri Apr 25 11:53:02 2003
Here's a short history: I'm working on an interactive fiction engine, and
I'd like to create a list of verbs dynamically, based on the classes
created.
My current solution is to define the class, then run a verb-grabber
function right after that definition:
import wordlist
def getActions (thingClass):
for m in dir (thingClass):
if m [:4] == 'act_':
wordlist.addVerb (m [4:])
# Player class, where act_* defines a verb
class Player (Thing):
def __init__ (self):
... code ...
def act_go (self, parsed):
... code ...
def act_look (self, parsed):
... code ...
getActions (Player)
---
My question is: Is there a function I can define in the base Thing class
which would run once Player (or any other Thing child) has been fully
defined? Or is my current solution as close as I can get?
---
Lastly, thanks for the quick answers to my last question! I'm looking
forward to being a contributing part of this list.
--
Zak Arntson
www.harlekin-maus.com - Games - Lots of 'em