Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > conditional import into global namespace

Reply
Thread Tools

conditional import into global namespace

 
 
mk
Guest
Posts: n/a
 
      03-02-2010
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?

I see a few possibilities:

1. do a class level import, like:

class TimeSync(object):

import subprocess


2. do an import in init, which is worse bc it's ran every time an
instance is created:

def __init__(self, shiftsec, ntpserver):
import subprocess


Both of those methods have disadvantage in this context, though: they
create 'subprocess' namespace in a class or instance, respectively.

Is there anyway to make it a global import?

Regards,
mk

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import Namespace using conditional compilation symbols Suresh ASP .Net 3 07-29-2008 12:17 AM
import and global namespace nate Python 3 07-12-2006 08:21 AM
How to import whole namespace into global symbol table? (newbie) Scott Simpson Python 2 04-28-2006 05:51 AM
? ELSE Conditional Comment / Using Conditional Comments Inside Other Tags To Comment Out Attributes Alec S. HTML 10 04-16-2005 02:21 AM
Reaching into the default namespace when using another namespace. Jason Heyes C++ 1 11-19-2004 02:36 AM



Advertisments