redundant imports

max(01)* max2 at
Thu Mar 31 17:48:27 CEST 2005

Tim Jarman wrote:
> max(01)* wrote:
>>hi everybody.
>>suppose that imports and (because it uses
>>names from both), and that imports
>>if python were c, code-1.c should only *include* code-2.c, because the
>>latter in turns includes code-3.c.
>>inclusion of modules in c is a purely preprocessing textual matter
>>(compilation is deferred to after the fact), i guess, so that such
>>things are possible. import of modules in python is a different beast,
>>so the "redundancy" is (i think) necessary.
>>any comment/suggestion/idea?
> It's not as redundant as it looks. 

that's why i used quotes ;-)

> Once a module has been imported it goes
> into sys.modules and any subsequent imports refer to that original import,
> so the overhead of reading and parsing the file is only incurred once. As
> you're probably aware, Python also caches compilation results in *.pyc
> files; it will only compile the imported module if it changed since the
> last compilation.

this leads me to another question. since *.pyc files are automatically 
created the first time an import statement in executed on a given 
module, i guess that if i ship a program with modules for use in a 
directory where the user has no write privileges then i must ship the 
*.pyc files along too. right?

> Check out the docs for the full skinny, in particular
> HTH,
> Tim J

thanks a lot



More information about the Python-list mailing list