CHAPTER FOUR EXECUTION MODEL 4.1 Structure of a program 4.2 Naming and binding 4.2.1 Binding of names 45 Each occurrence of a name in the program text refers to the binding of that name established by the following name resolution rules. If a name is bound in a block, it is a local variable of that block, unless declared as$_{nonlocal}$ or$_{global}$ . If a name is bound at the module level, it is a global variable. (The variables of the module code block are local and global.) If a variable is used in a code block but not defined there, it is a free variable . Each assignment or import statement occurs within a block defined by a class or function definition or at the module level (the top-level code block). A target occurring in a$_{del}$statement is also considered bound for this purpose (though the actual semantics are to unbind the name). The following constructs bind names: formal parameters to functions,$_{import}$ statements, class and function def- initions (these bind the class or function name in the defining block), and targets that are identifiers if occurring in an assignment,$_{for}$ loop header, or after$_{as}$ in a$_{with}$ statement or$_{except}$clause. The$_{import}$ statement of the form$_{from ... import *}$ binds all names defined in the imported module, except those beginning with an underscore. This form may only be used at the module level. Names refer to objects. Names are introduced by name binding operations. A code block is executed in an execution frame . A frame contains some administrative information (used for debug- ging) and determines where and how execution continues after the code block’s execution has completed. A Python program is constructed from code blocks. A block is a piece of Python program text that is executed as a unit. The following are blocks: a module, a function body, and a class definition. Each command typed interactively is a block. A script file (a file given as standard input to the interpreter or specified as a command line argument to the interpreter) is a code block. A script command (a command specified on the interpreter command line with the -c option) is a code block. A module run as a top level script (as module$_{__main__}$ ) from the command line using a$_{-m}$argument is also a code block. The string argument passed to the built-in functions$_{eval()}$ and$_{exec()}$ is a code block.