conditional import into global namespace

M

mk

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top