[Tutor] function declaration problems perhaps?

Kent Johnson kent37 at tds.net
Wed Jul 25 17:59:24 CEST 2007


Alan Gauld wrote:
> "nibudh" <nibudh at gmail.com> wrote
> 
>> in perl this works:
>>
>> #!/usr/bin/env perl
>> hello("World");
>>
>> sub hello {
>>    print "Hello ". $_[0] . "\n";
>> }
> 
> 
> 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. For imported modules it saves 
the compiled bytecode in a .pyc file, but not for directly-executed 
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.

Kent


More information about the Tutor mailing list