Beautiful Python

Jarek Zgoda jzgoda at o2.usun.pl
Mon Dec 26 06:53:54 EST 2005


Gekitsuu napisal(a):

> 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.

Sometimes putting import statements at the beginning is not feasible
(i.e. only when some condition has been met), as importing has some
impact on program execution (importing executes code in imported
module). This does not resemble Java imports (I don't know Perl).

-- 
Jarek Zgoda
http://jpa.berlios.de/



More information about the Python-list mailing list