[Tutor] Global name not found, though clearly in use

Emile van Sebille emile at fenx.com
Wed Jul 14 22:37:42 CEST 2010


On 7/14/2010 11:11 AM Serdar Tumgoren said...
>But I was wondering (for my own
> edification), can anyone point to the portion of the docs that clearly
> spells out the order of execution (top to bottom, classes vs. functions,
> etc.).

I found this in the tutorial in the modules section:
   ( see http://docs.python.org/tutorial/modules.html )

    "A module is a file containing Python definitions and statements."

Ergo, stuff that executes and stuff that defines.

Further clarification provided:
"""A module can contain executable statements as well as function 
definitions. These statements are intended to initialize the module. 
They are executed only the first time the module is imported somewhere."""

... and a Footnote:
"""In fact function definitions are also statements that are executed; 
the execution of a module-level function enters the function name in the 
modules global symbol table."""

The same applies to the class namespaces created and the contained defs.

As to the execution order, that's apparently buried in the c sources of 
the scanner and tokenizer bits.  I didn't see anything more specific 
than "stream processing" and "*file" pointers hinting at serial 
processing of the source py file.


I also found this interesting (but possibly not to newbies :) :
   http://www.shinetech.com/attachments/108_python-language-internals.pdf

Emile



More information about the Tutor mailing list