Self-modifying Code

qwweeeit at yahoo.it qwweeeit at yahoo.it
Thu May 19 13:10:47 EDT 2005


Hi all,

when I was young I programmed in an interpreted language that allowed
to modify itself.
Also Python can (writing and running a module, in-line):

fNew =open("newModule.py",'w')
lNew=['print 123\n','print 454\n','print 789\n']
fNew.writelines(lNew)
fNew.close()
from newModule import *

Running this small example it correctly displays:
123
456
789

Did you know? Certainly someone has already discovered and applied
that, because the applications are several (think only to the
possibility of reducing code length by eliminating the coding of false
alternatives, or the possibility to convert a list of instructions
taken somewhere in a running code...)

Bye.




More information about the Python-list mailing list