Importing again and again

Dustan DustanGroups at gmail.com
Thu Jun 8 16:32:36 EDT 2006


abcd wrote:
> If I have code which imports a module over and over again...say each
> time a function is called, does that cause Python to actually re-import
> it...or will it skip it once the module has been imported??
>
> for example:
>
> def foo():
>     import bar
>     bar.printStuff()
>
> foo()
> foo()
> foo()
> foo()
>
> ...will that re-import bar 4 times...or just import it once?  is this a
> big performance hit?
>
> thanks

I don't really know, but I do know that the right way to re-import a
module is:

reload(bar)




More information about the Python-list mailing list