~/talk

Bytecode and .pyc files

Talkat PyCon Italia 2025 · 2025-05-28..05-31· [compilers-and-language-design]
links:none on file
slides:none on file

Deep dive into CPython bytecode and .pyc internals: how co_code, co_consts and co_varnames map to evaluation stack operations and instructions like LOAD_CONST, LOAD_GLOBAL, CALL_FUNCTION and BINARY_OP; how .pyc headers store a magic number and timestamp (or hashed variant) and why __pycache__ names include the Python version; tools shown include dis and dis.get_instructions, marshal for reading code objects, and creating functions with FunctionType and code.replace to patch one byte and change an operator — the edit works and executes.

AI-written summary · about

  1. 0:00Introduction
  2. 1:11What is bytecode
  3. 3:22Bytecode vs machine code
  4. 4:31Inspecting bytecode
  5. 8:24Stacks in execution
  6. 17:27Why .pyc files matter
  7. 19:58Optimizing with .pyc files
  8. 21:03Inside .pyc files
  9. 22:51Bytecode optimization levels
  10. 23:34Exception handling in bytecode
  11. 24:18Dynamic function creation
  12. 28:15Practical bytecode tricks
  13. 29:51Q&A
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.