Skip to content

Instantly share code, notes, and snippets.

@wwhtrbbtt
Created May 4, 2021 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wwhtrbbtt/43561df4cbe08697712d2232037d5b02 to your computer and use it in GitHub Desktop.
Save wwhtrbbtt/43561df4cbe08697712d2232037d5b02 to your computer and use it in GitHub Desktop.
import sys
import json
file = "file.ipynb"
with open(file, "r") as f:
raw = f.read()
lines = []
try:
for cell in json.loads(raw)["cells"]:
if cell["cell_type"] == "code":
lines += cell["source"]
except:
print("Couldnt find code in file")
quit()
for line in lines:
if line.startswith("#@markdown"):
print("## " + line)
continue
print(line, end="")
@wwhtrbbtt
Copy link
Author

A small script to convert iPython files to normal python sourcecode. Warning: iPython functions have to be removed manually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment