Re: How to access object attributes given a string

2008-02-14 Thread Santiago Romero
> >> You are using a scripting language.. why not use python directly? > > > I just want to execute an small set of commands (PLAYSOUND, PLAYMUSIC, > > WALKTO, PLAYERSAY, SLEEP and a couple more) ... do you think I can > > write python code inside my object.exec (list attribute) loaded from a > > f

Re: How to access object attributes given a string

2008-02-13 Thread Gabriel Genellina
En Tue, 12 Feb 2008 18:53:36 -0200, Santiago Romero <[EMAIL PROTECTED]> escribió: >> Dennis Kempin wrote: >> You are using a scripting language.. why not use python directly? > > I just want to execute an small set of commands (PLAYSOUND, PLAYMUSIC, > WALKTO, PLAYERSAY, SLEEP and a couple more) .

Re: How to access object attributes given a string

2008-02-12 Thread Santiago Romero
This is faster: http://www.sromero.org/python/zx_parseexec.py http://www.sromero.org/python/test.par XD -- http://mail.python.org/mailman/listinfo/python-list

Re: How to access object attributes given a string

2008-02-12 Thread Santiago Romero
And the rest of the code: # def ExecParser_Exec( exec_type, code, game, debug=0 ): """ Execute the previously "compiled" code: """ code_level = 0 #player = game.player #world = game.world # Take only opco

Re: How to access object attributes given a string

2008-02-12 Thread Santiago Romero
And the big functions: I imagine that the following is HORRIBLE in the pythonic-vision and surely can be rewriten with a single map+reduce+filter + 200 lambdas functions X-D, but I come from C and any advice on how to implement my "simple scripting language" without using lex or yacc is welcome

Re: How to access object attributes given a string

2008-02-12 Thread Santiago Romero
Before I reinvent the wheel, I'm going to post the code. Feel free to give any advice, and think that I'm new to python, it's only 1 month since I began programming in python "seriously" (up to that moment, I wrote just a few log-text parsing system administration scripts to speed up some old b

Re: How to access object attributes given a string

2008-02-12 Thread Steve Holden
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

Re: How to access object attributes given a string

2008-02-12 Thread Santiago Romero
> > def ChangeAttribute( object, attribute, value ): >help(setattr) > > Help on built-in function setattr in module __builtin__: > > setattr(...) setattr(object, name, value) > > Set a named attribute on an object; setattr(x, 'y', v) is > equivalent to`x.y = v''. and > Gary Herron write: > Yo

Re: How to access object attributes given a string

2008-02-12 Thread [EMAIL PROTECTED]
On 12 fév, 21:35, Dennis Kempin <[EMAIL PROTECTED]> wrote: > Santiago Romero schrieb: (snip - others already answered) > > 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 )". > > You are using a sc

Re: How to access object attributes given a string

2008-02-12 Thread Dennis Kempin
Santiago Romero schrieb: > 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 ): > # Inse

Re: How to access object attributes given a string

2008-02-12 Thread Gary Herron
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 he

Re: How to access object attributes given a string

2008-02-12 Thread Chris
On Feb 12, 10:25 pm, Santiago Romero <[EMAIL PROTECTED]> 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( o