Importing again and again

John Bokma john at castleamber.com
Thu Jun 8 18:42:33 EDT 2006


"Terry Reedy" <tjreedy at udel.edu> wrote:

> 
> "John Bokma" <john at castleamber.com> wrote in message 
> news:Xns97DCA4EEBEBEEcastleamber at 130.133.1.4...
>>> def foo():
>>>     import bar
>>>     bar.printStuff()
>> I am new to Python so this might be a weird question, but it there a
>> reason why you import bar inside foo?
> 
> Two possible reasons:
> 1) delay import until actually needed, if ever.
> 2) put 'bar' into the function local namespace instead of the module
> global namespace

OK clear and thanks. I was guessing the later, and the first one I 
overlooked (Perl works different, you have to do the delay yourself).

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