Hey all, I have a question on using self-modifying code/code generation in 
Python;
namely how to do it. 


I've posted on Stack Overflow and a python forum on this topic, and apparently 
the current approach I'd devised was....too difficult.
The idea was, for every Python operator and statement and whatnot, having a 
corresponding class/block of code with which to use it, and 

then using 'exec' to execute the statements...

The first problem here, of course, is that it isn't a self-modifying system at 
all....second being there'd be no way to edit pre-existing code, and getting it 
all to be deleted wouldn't...make any sense.

People have recommended the use of Python's AST module, along with the Compile 
module, to be able to programatically edit/change pre-existing code, but there 
are two problems here. One being I'm not familiar at all with the AST/Compile 
modules, and two being that to the best of my understanding the AST module is 
very difficult for a user, let alone a Python code, to manipulate to yield 
useful results. (in case your wondering, I was hoping to hook up whatever form 
of modification/generation to a genetic algorithim or backprop algorithim and 
hopefully get something that can automatically write simple codes....idk)

My question is....what should I be doing? Would the AST module work? Or am I 
jst being overly-ambitious?
-Aaron

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to