redundant imports
max(01)*
max2 at fisso.casa
Thu Mar 31 10:48:27 EST 2005
Tim Jarman wrote:
> max(01)* wrote:
>
>
>>hi everybody.
>>
>>suppose that code-1.py imports code-2.py and code-3.py (because it uses
>>names from both), and that code-2.py imports code-3.py.
>>
>>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?
>>
>>bye
>>
>>macs
>
>
> 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
> http://www.python.org/doc/2.4/ref/import.html
>
> HTH,
> Tim J
>
thanks a lot
bye
macs
More information about the Python-list
mailing list