Question about using python as a scripting language
Steve Lianoglou
slianoglou at gmail.com
Sun Aug 6 22:44:30 EDT 2006
Hi,
> I was wondering how I can read
> commands from the XML file and then execute them in the game.
...
> I just need some way of
> being able to read from the file what function the program needs to
> call next. Any help is appreciated.
One thing you could do is use the eval or compile methods. These
functions let you run arbitray code passed into them as a string.
So, for instance, you can write:
my_list = eval('[1,2,3,4]')
and my_list will then be assigned the list [1,2,3,4], moreover:
eval("my_list.%s" % "reverse()")
or ... even further .. :-)
command = "reverse"
eval("my_list.%s()" % "reverse")
will reverse my_list
Is that something like what you're looking for?
-steve
More information about the Python-list
mailing list