Importing again and again

John Bokma john at castleamber.com
Thu Jun 8 17:12:49 EDT 2006


"abcd" <codecraig at gmail.com> 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?

I am new to Python so this might be a weird question, but it there a 
reason why you import bar inside foo?

-- 
John                               MexIT: http://johnbokma.com/mexit/
                           personal page:       http://johnbokma.com/
        Experienced programmer available:     http://castleamber.com/
            Happy Customers: http://castleamber.com/testimonials.html



More information about the Python-list mailing list