Python
Alternative Interpreters & Compilers
27 flashcards · answers and spaced-repetition review in the KnowCard app
When someone says "Python," which implementation do they almost always mean, and what does that implementation actually produce from your source?
A coworker says "Python is compiled — that's what the .pyc files in __pycache__ are: machine code." What's wrong?
What makes PyPy faster than CPython on the right workload, and what is the mechanism called?
You swap CPython for PyPy on a script that mostly reads files from disk and waits on the network. Will it speed up much? Why or why not?
What's the main risk of dropping PyPy into an existing project, beyond "it's a different interpreter"?
Is Cython just "a faster Python interpreter" you run your .py files with? If not, what is it?
Roughly how much can plain, unmodified Python code speed up after just compiling it with Cython, and where does the *big* Cython speedup actually come from?
You add C type declarations like cdef int tmp to a .pyx file for speed. Can you still run that same file directly with the normal python command?
Besides speeding up your own code, what's the other core use case Cython is built for?
Jython and IronPython let you run Python on the JVM and .NET. What's the standing caveat to remember before betting a project on one?
What is the GIL in CPython, and why does its existence motivate alternatives like Cython's nogil or other interpreters?
Your manager wants to "ship the Python app as a single .exe so users don't install Python." Does compiling/Cython give you that, and what actually does?
Numba speeds up numeric code with a @numba.jit decorator. With plain @numba.jit, what happens to parts of your function Numba can't compile — and how is @numba.njit different?
Why do all IPython "magic functions" begin with a % sign, and how do you look up what a particular one does?
You want to benchmark an expression in IPython. What's the difference between the %time, %timeit, and %prun magic functions?
A Jupyter (formerly IPython) Notebook document is "a sequence of cells." What are the four basic cell types, and which one holds runnable Python?
In a Jupyter markdown cell, how do you make bold text and render a math formula — and what magic makes matplotlib plots appear inline in the notebook?
Numba and PyPy both do JIT compilation, but Numba is not a separate interpreter. What does the @numba.jit decorator actually translate your function into, where can it run it, and what kind of code is it built for?
You decorate a tiny helper with @numba.jit and call it just a couple of times; it ends up slower than plain Python. How can Numba make code slower, and when does it actually pay off?
pip install cython succeeded, but building your .pyx extension fails on a fresh Windows machine with compiler errors. What's the likely missing piece, and how do you fix it on Windows specifically?
In a .pyx file you write def sort(int[:] values): and then cdef int tmp. What does int[:] mean, which Python objects can you pass to it, and what does cdef do?
To call C's qsort from Cython you write from libc.stdlib cimport qsort. Why cimport instead of import, and what do you do when Cython has no ready-made header for the C library you need?
In a Cython declaration such as cdef extern from "<stdlib.h>" nogil: (or on a cdef function), what does the nogil keyword permit, and why would you want it?
Read this Cython comparison callback: return (<int>a)[0] - (<int>b)[0], then the call qsort(&values[0], len(values), sizeof(int), compare). What does each piece of pointer/C syntax do?
IPython is described as more than a nicer REPL — it "separates the shell from the underlying interpreter." What is IPython, and what does that separation make possible?
At an IPython prompt you type x? and then x??. What does each print, and how does this compare to plain help(x)?
IPython prompts look like In [7]: with a number in brackets. What is that number, and what's the difference between the %rerun and %history magic functions?
Start learning today
Free to start — download the app or use it in your browser.
