[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Re: conditional import into global namespace

Jerry Hill

3/2/2010 6:31:00 PM

On Tue, Mar 2, 2010 at 12:46 PM, mk <mrkafk@gmail.com> wrote:
> Hello everyone,
>
> I have a class that is dependent on subprocess functionality. I would like
> to make it self-contained in the sense that it would import subprocess if
> it's not imported yet.
>
> What is the best way to proceed with this?

Just import subprocess at the top of your module. If subprocess
hasn't been imported yet, it will be imported when your module is
loaded. If it's already been imported, your module will use the
cached version that's already been imported.

In other words, it sounds like Python already does what you want. You
don't need to do anything special.

--
Jerry