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

Serdar Tumgoren zstumgoren at gmail.com
Wed Jul 14 20:11:44 CEST 2010


>  Hmm..If I add a few debugging lines like that into my code, I get this:
>>
>
> The point was that statements in a class at class level (ie, not in defs)
> are executed sequentially and expect referenced variables to exist (ie,
> defined somewhere 'above' the current statement) -- there is no forward
> peeking going on.  Statements within def's (think 'deferred execution' if it
> helps) expect that the variables referred to will exist by the time the def
> is invoked.
>
> Python executes code top to bottom.  def's create an executable object and
> defers execution until invoked.  Other statements execute when encountered.
>  The statements in your class that start
>
>
Aside from other scattered problems with the code, Emile's explanation seems
to get at the core of the OP's confusion. 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.). The only place I've encountered such a discussion of execution order
was in Chapter 2 of Pro Django, and the below doc pages don't seem to
address the issue head-on (unless I'm misunderstanding or missed something):

http://docs.python.org/tutorial/classes.html
http://docs.python.org/reference/executionmodel.html

Thanks!
Serdar
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20100714/98751dda/attachment.html>


More information about the Tutor mailing list