Skip to content

Instantly share code, notes, and snippets.

@Touchcreator
Created May 20, 2025 15:58
Show Gist options
  • Save Touchcreator/58ec03526ed957c8a4c16378365f2d40 to your computer and use it in GitHub Desktop.
Save Touchcreator/58ec03526ed957c8a4c16378365f2d40 to your computer and use it in GitHub Desktop.
basically, i was in school, and i got bored and was like "what if python used include instead of import?" so i made this
import os
import tempfile
import subprocess
filename = "test.py"
alreadyincluded = []
with open(filename) as f:
fullfile = f.read()
filesplitlines = fullfile.splitlines()
newfile = ""
newsplitlines = []
for line in filesplitlines:
newsplitlines.append(line)
try:
if line.split()[0] == "#include":
filetoinclude = line.split()[1]
with open(filetoinclude) as f:
filecontents = f.read()
if not (filetoinclude in alreadyincluded):
newsplitlines.append(filecontents)
try:
if filecontents.splitlines()[0] == "#pragma once":
alreadyincluded.append(filetoinclude)
except:
pass
except:
pass
realcode = ""
for line in newsplitlines:
realcode += line + "\n"
with tempfile.TemporaryDirectory() as tmpdir:
tmppyfile = os.path.join(tmpdir, "temp.py")
with open(tmppyfile, "w") as py:
py.write(realcode)
subprocess.call(["python", tmppyfile])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment