The locals () built-in function prints a local character table that is bound to a code object and populated when the interpreter receives a name in the source code.
The second example, when disassembling, contains the LOAD_GLOBAL foo bytecode command in b . This LOAD_GLOBAL command will move up the field, find the external name foo and associate it with the code object, adding the name offset to the co_names attribute of the object of the closing code (function b).
Function
locals () prints a table of local characters (as mentioned earlier, the co_names attribute of the function code object).
Read more about code objects here .
source share