Beautiful Python

Gekitsuu gekitsuu at gmail.com
Mon Dec 26 05:01:07 EST 2005


I've been reading a lot of python modules lately to see how they work
and I've stumbled across something that's sort of annoying and wanted
to find out of there was a good reason behind it. In a Perl program
when you're calling other modules you'll add "use" statements at the
beginning of your script like:

use strict;
use WWW::Mechanize;
use CGI;

This seems to be the de facto standard in the Perl community but in
python it seems most of the code I look at has import statements
everywhere in the code. Is there a sound reason for putting the imports
there are are developers just loading modules in as they need them. I
own Damian Conway's book of Perl Best Practices and it seems from a
maintainability standpoint  that having all the modules declared at the
beginning would make it easier for someone coming behind you to see
what other modules they need to use yours. Being new I didn't know if
there was a performance reason for doing this or it is simply a common
habit of developers.




More information about the Python-list mailing list