[Tutor] The Best Way to go About with Self Modifying Code/Code Generation?

Stefan Behnel stefan_ml at behnel.de
Sun Jul 8 07:51:12 CEST 2012


Aaron Tp, 07.07.2012 23:19:
> I have a question on using self-modifying code/code generation
> in Python; namely how to do it.

Don't.

Seriously, the answer you should ask yourself is: why do you think the
genetic algorithm (or whatever you are trying to do exactly) would come up
with any reasonable code constructs other than what you already
anticipated? And if you anticipated them, you can just write them down
statically in the code and only care about recombining them.

Make your code configurable instead, and then change the configuration. I
agree with Alan that a state machine could be a suitable approach (but it's
a bit hidden in his long answer). In any case, think in terms of modifying
data, not code.

Stefan



More information about the Tutor mailing list