finding name of instances created

Michael Tobis mt at 3planes.com
Sun Jan 23 15:50:17 EST 2005


I have a similar problem. Here's what I do:

.def new_robot_named(name,indict=globals()):
.   execstr = name + " = robot('" + name + "')"
.   exec(execstr,indict)

.class robot(object):
.   def __init__(self,name):
.      self.name = name

.   def sayhi(self):
.      print "Hi!  I'm %s!" % self.name

.if __name__=="__main__":
.   new_robot_named('Bert')
.   new_robot_named('Ernie')
.   Ernie.sayhi()
.   Bert.sayhi()




More information about the Python-list mailing list