reading-notes

Software Development Reading Notes

View on GitHub

Python Scope

The concept of scope rules how variables and names are looked up in your code.
It determines the visibility of a variable within the code.

functions and classes are available after you define them using 'def' or 'class'
modules exist after you import them. 

Name space

>>> import sys
>>> sys.__dict__.keys()
dict_keys(['__name__', '__doc__', '__package__',..., 'argv', 'ps1', 'ps2'])

dict holds the namespace of sys and is a concrete representation of the module scope.

LEGB Rule

Unusual Python Scope