I have made a quine. it's a mess but I think it will be readable enough. It is made to both write itself to a file and write itself in cmd. When it writes itself in cmd it writes with a short delay between each letter. All of that works.
What doesn't work is that it is supposed to start the new file after having written it. That is to say, it works fine for the first and second file, but at the third it stops.
import time
import sys
import re
import os
#Figure out the number of the current file, and add 1.
name = os.path.basename(__file__)
t = str(int(re.findall(r'\d+',name)[0])+1)
#The first string to write.
s='\n\n\nimport time ' \
'\nimport re' \
'\nimport os' \
'\nimport sys ' \
'\n\nname = os.path.basename(__file__)' \
'\nt = str(int(re.findall(r"\d+",name)[0])+1)' \
'\n\ns=%r ' \
'\n\nfor l in s%%s:' \
'\n sys.stdout.write(l)' \
'\n sys.stdout.flush()' \
'\n time.sleep(0.05) ' \
'\n\nfile = open("stolen"+t+".py", "w+") ' \
'\nfile.write(s%%s)'
#Write the above string slowly in cmd
for l in s%s:
sys.stdout.write(l)
sys.stdout.flush()
time.sleep(0.00005)
#Create and open the new file and write to it
file = open("stolen"+t+".py", "w+")
file.write(s%s)
#second string to write
s='\n\ns=%r ' \
'\n\nfor l in s%%s:' \
'\n sys.stdout.write(l)' \
'\n sys.stdout.flush()' \
'\n time.sleep(0.05) ' \
'\n\nfile = open("stolen"+t+".py", "a") ' \
'\nfile.write(s%%s)'
#write slowly
for l in s%s:
sys.stdout.write(l)
sys.stdout.flush()
time.sleep(0.00005)
#write to file
file = open("stolen"+t+".py", "a")
file.write(s%s)
#new string
s='\n\ns=%r ' \
'\n\nfor l in s%%s:' \
'\n sys.stdout.write(l)' \
'\n sys.stdout.flush()' \
'\n time.sleep(0.05) ' \
'\n\nfile = open("stolen"+t+".py", "a") ' \
'\nfile.write(s%%s)'
#write slowly
for l in s%s:
sys.stdout.write(l)
sys.stdout.flush()
time.sleep(0.00005)
#write to file
file = open("stolen"+t+".py", "a")
file.write(s%s)
#new string
s='\n\ns=%r ' \
'\n\nfor l in s%%s:' \
'\n sys.stdout.write(l)' \
'\n sys.stdout.flush()' \
'\n time.sleep(0.05) ' \
'\n\nfile = open("stolen"+t+".py", "a") ' \
'\nfile.write(s%%s)' \
'\n\nimport subprocess' \
'\n\nsubprocess.call("python stolen"+t+".py 1", shell=True)'
#write slowly
for l in s%s:
sys.stdout.write(l)
sys.stdout.flush()
time.sleep(0.00005)
#write to file
file = open("stolen"+t+".py", "a")
file.write(s%s)
file.close()
#forgot to import this
import subprocess
#run new file
subprocess.call("python stolen"+t+".py 1", shell=True)
What seemingly happens is the when stolen2.py runs it doesn't write the "run new file" part. I have no idea why this happens. I'm hoping someone can help me figure this out.
EDIT: something strange I have found out is that the more times you have the below code, the more files are created.
s='\n\ns=%r ' \
'\n\nfor l in s%%s:' \
'\n sys.stdout.write(l)' \
'\n sys.stdout.flush()' \
'\n time.sleep(0.05) ' \
'\n\nfile = open("stolen"+t+".py", "a") ' \
'\nfile.write(s%%s)'
#write slowly
for l in s%s:
sys.stdout.write(l)
sys.stdout.flush()
time.sleep(0.00005)
#write to file
file = open("stolen"+t+".py", "a")
file.write(s%s)