Python - Self-Modding Code


/ Published in: Python
Save to your folder(s)

One day I got to wondering if it was possible to get a Python script to modify itself. After a few searches I found a solution that I present here. I did not write this code, but feel that it should be "paid forward" so others know that it is possible, and how to accomplish it. Basically the script reads itself into a variable, then REs the time stamp line which is then replaces with a new one. Next the modified code is saved back down. I could actually see a genetic algo modding itself as it goes so that it writes an optimal version of itself at the end. Pretty cool. NOTE: A backup function should be added for safety.
Original code site: http://showmedo.com/videotutorials/video?name=7610000&#

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.