If you have used so many softwares, you might have come across some that shows some Tips dialog with a checkbox that says "Show tip on startup." If you get annoyed, you uncheck it. It won't appear next time.
Guess how it is programmed. There must be some kind of a properties file or database that stores some boolean (or any other form of data) to store this setting. And everytime the application is loaded, it checks for the variable unnecessarily wasting cycles. It won't remember that you said you don't want to see any tips. It's like an unintelligent being (which is what it is.. afterall it's just a set of instructions.) Metaprograms can be made to look intelligent (from developer's point of view.)
This program is a very basic example. It prints out Hello and Good Morning. It asks you whether you want to be greeted with Hello everytime. If you say no, then it removes the related code from itself. IT CHANGES ITSELF! (Does it sound like Matrix? I Robot? Bicentennial Man?) It changes itself like the frogs in Jurassic Park novel.
CODE:
def deleteHello():
f = open("sixthsense.py","r")
output = []
for line in f:
if not line.endswith("deleted#\n"):
output.append(line)
f.close()
f = open("sixthsense.py","w")
f.writelines(output)
f.close()
print "Hello" #line that might be deleted#
raw_input() #line that might be deleted#
print "Good Morning"
raw_input()
choice = raw_input("Should I greet you with Hello always? (y/N)") #line that might be deleted#
if choice != "y": #line that might be deleted#
deleteHello() #line that might be deleted#
Remember to copy the file before running as you know that it can change itself.
PS:
One interesting thing happened.. I made a foolish mistake.
Before this condition,
if not line.endswith("deleted#\n"):
I actually used this line.
if not "#line" in line:
That was really stupid. Because the condition line itself satisfies the condition and gets removed. :P