How to execute lists of code? Or alternatives.

rzantow at my-deja.com rzantow at my-deja.com
Tue May 9 15:37:34 CEST 2000


Is there a way to execute a list of Python code strings?

What I'd like to do is to create a dictionary of tags and,
among other things, associated code. When parsing a file and
encountering one of the tags, I'd then execute the associated
code. I could do this if the code fragments were contained in
separate files, using exec_file(), but I'd rather not have to
either create a host of tiny files or a large file with a
long string of if...elif conditions.

I'd expect the code to be built up, in a manner of speaking,
by applying a generic dictionary to handle the known tags,
and adding new tag-handling and overrides for a given program
run. I would prefer that the new/overrides stuff be maintained
in a single file, but associated at run time with the individual
tags.

Has anyone done this? Can anyone point out the likely better way
to do something like it?

The limitation I'm looking at is that it would not likely be
programmers maintaining the new/overrides material. I would expect
that knowledgeable users and programmatic wizards would be used
to build up that code, except in unusual circumstances.

Any comments?

--
Pythons, unlike some other snakes, do have hindlimbs, but they never
develop beyond vestigial stumps. The arrest of limb development is
due to a failure of the sonic hedgehog signalling system ...


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list