File Handling · Python example
Create a file in Python's virtual filesystem, then read it back.
Python can read and write files. In the browser, these files live in Pyodide's in-memory filesystem and disappear when the runtime restarts.
filename = "ilovecompiler_notes.txt"
with open(filename, "w", encoding="utf-8") as file:
file.write("ILoveCompiler file demo\n")
file.write("Second line\n")
with open(filename, encoding="utf-8") as file:
contents = file.read()
print(contents, end="")