"Kent Johnson" <[EMAIL PROTECTED]> wrote

>> Perl executes differently to Python in that it does a compilation
>> stage before executing. Therefore Perl knows about all the function
>> definitions prior to executing any code. Python compiles modules 
>> which it imports
>> but not scripts which it executes.
>
> Python compiles all scripts to bytecode.

Doh! Yes of course it does, stoopid me.

> scripts. However this has no bearing on the current thread; for both
> imported modules and executed scripts, a function must be defined 
> before
> it can be called.

Yes, the bearing is in the way that Perl compiles its code.
Perl builds a name tree from the entire file before executing
so it doesn't rely on the order of definition, Python seems
to compile and execute code in a sequential manner and
therefore relies on the sequence being right.

I'm not sure if the undefined name errors come from the compilation
or from the execution - does anyone else. I confess i've never looked
deeply into how Python actually does its complile/execute cycle.

Alan G. 


_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to