How global variables work in Python bytecode

Hi again! A couple weeks ago I shared a post about local variables in Python bytecode, and now I’m back with a follow-up on globals.

Global variables are handled quite differently than locals. Instead of being assigned to slots, they’re looked up dynamically at runtime using the variable name. The VM has a much more active role in this than I expected!

If you’re curious how this works under the hood, I hope this post is helpful: https://fromscratchcode.com/blog/how-global-variables-work-in-python-bytecode/

As always, I’d love to hear your thoughts or questions!

submitted by /u/19forty to r/Python
[link] [comments]


Commentaires

Laisser un commentaire

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *