Limits of Metaprogramming

John Nagle nagle at animats.com
Mon Aug 4 11:50:18 EDT 2008


Wilson wrote:
> Hi all,
> 
> I have an interesting problem that I'm hoping can be solved with
> metaprogramming, but I don't know how far Python supports code
> generation (and I don't know if I'm taking the correct approach
> either... hence why I'm asking on this group):
> 
> I'd like to write a program that writes/manipulates a statemachine. My
> idea was that I would define states in a .py file along with their
> transitions and other metadata.

    You're probably better off coming up with a representation for a
state machine (which might be a pickled collection of Python objects)
then providing a "compile" operation which cranks out a .py file
with code to implement the state machine.

				John Nagle



More information about the Python-list mailing list