[Tutor] (no subject)

Alan Gauld alan.gauld at freenet.co.uk
Mon Dec 5 22:16:29 CET 2005


> i guess i need to pass wield an object somehow instead of a string.
> can anyone point in the right direction?

AS ever converting strings to objects is a job for a doictionary. And 
remember that classe3s are objects too.

So simply register each class you define in a dictionary of classes against 
their name

classes = {'Room':Room, 'Player': Player, 'Sword':Sword,...}

class Player:
       def wield(self,what):
         print type(what)
         print 'you wield',what
         self.wielded = classes[what]()   # an instance of what...

HTH,

Alan G
Author of the learn to program web tutor
http://www.freenetpages.co.uk/hp/alan.gauld




More information about the Tutor mailing list