Santiago Romero wrote: > Hi... > > I'm trying to guess how to access attributes of an existing object > given the attribute name in a string. I mean: > > class Object: > self.x = 12 > self.y = 20 > self.name = "blah" > > def ChangeAttribute( object, attribute, value ): > # Insert here the code for object.attribute = value > XXXXX > > Allowing this kind of calls: > > ChangeAttribute( object, "x", 200 ) > ChangeAttribute( object, "name", "my name" ) > > Thanks. > > PS: I need it for a concrete case in a game scripting language I'm > writing, so that I can call functions like "CHANGE_PLAYER_VALUES( "x", > 100 )".
Look in the documentation for gettattr() and setattr(). regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119 Holden Web LLC http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list