
Warning
This page shows last year’s version. We might still make small changes, but you’re welcome to take a look. We’ll remove this notice once the page is final.
Week 13: Closure#
Syllabus#
User-made modules, using them and creating them
Import statements, standard import, selective import and alias import
The
dir()function
Before the exam#
At the exam you will not have access to the internet.
If you want to use any of the course material, you will need to download it before the exam. Run the script below to download the course webpage as HTML files.
You can also download the website as pdf files course_material_as_pdf.zip.
If you want to access the book, you have to download it yourself.
import os
import urllib.request
base = "https://programmering.compute.dtu.dk/"
mathjax = "https://cdn.jsdelivr.net/npm/mathjax@4/tex-mml-svg.js"
files = ["_static/basic.css", "_static/vendor/fontawesome/webfonts/fa-solid-900.woff2"] # only used by css files
for name in ["prerequisites", "executing", "reading", "syllabus", "policies", "FAQ"]:
files.append(f"additional/{name}.html")
for week in range(1, 14):
for kind in ["prep", "inclass", "closure", "advanced"]:
files.append(f"weeks/week{week:02}_{kind}.html")
for file in files: # the files used by the pages are added to the list during the loop
path = os.path.join("programmering_html", file)
os.makedirs(os.path.dirname(path), exist_ok=True)
print(f"Downloading {file}...")
urllib.request.urlretrieve(base + file, path)
if file.endswith(".html"): # for html files we replace with local links, and find undownloaded pages
with open(path, encoding="utf-8") as f:
text = f.read()
for part in text.split('"../')[1:]: # links look like "../folder/file?v=123"
link = part.split('"')[0].split("?")[0]
if link != "" and ".html" not in link and link not in files:
files.append(link)
with open(path, "w", encoding="utf-8") as f:
f.write(text.replace(mathjax, "../_static/mathjax.js")) # use our own copy of MathJax
urllib.request.urlretrieve(mathjax, os.path.join("programmering_html", "_static", "mathjax.js"))