Created
August 6, 2011 01:18
-
-
Save Ming-Tang/1128876 to your computer and use it in GitHub Desktop.
Quine program that saves state by outputting its own source code and session data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from time import gmtime, strftime;data = { } | |
while True: | |
inp = raw_input().split(" ") | |
if inp[0] == '*': | |
data = { } | |
elif len(inp) < 2: | |
break | |
else: | |
if inp[0] == '!': | |
del data[inp[1]] | |
elif inp[0] == '?': | |
if inp[1] in data: | |
print data[inp[1]] | |
else: | |
data[inp[0]] = inp[1] | |
def quine(source): | |
global data | |
f = open('session' + strftime("%Y-%m-%d-%H-%M-%S", gmtime()) + '.py', 'w') | |
quote = '"' * 3 | |
f.write('from time import gmtime, strftime;data = ' + repr(data) + source + '(' + quote + source + quote + ')') | |
f.close() | |
quine(""" | |
while True: | |
inp = raw_input().split(" ") | |
if inp[0] == '*': | |
data = { } | |
elif len(inp) < 2: | |
break | |
else: | |
if inp[0] == '!': | |
del data[inp[1]] | |
elif inp[0] == '?': | |
if inp[1] in data: | |
print data[inp[1]] | |
else: | |
data[inp[0]] = inp[1] | |
def quine(source): | |
global data | |
f = open('session' + strftime("%Y-%m-%d-%H-%M-%S", gmtime()) + '.py', 'w') | |
quote = '"' * 3 | |
f.write('from time import gmtime, strftime;data = ' + repr(data) + source + '(' + quote + source + quote + ')') | |
f.close() | |
quine""") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment