0

I have two different packages with the same name, each with a set of modules and classes with the same names as each other but they are implemented differently. What is the most logical manner to set up my package/module structure?

Right now I'm doing something like:

  Common
    utilities.py
    VersionA
      Package
        moduleX.py
        moduleY.py
    VersionB
      Package
        moduleX.py
        moduleY.py

I am requiring that the environment where the modules are being used, just set the path to point to the correct version of "Package".

On top of it, there is one module that both packages share! "Utilities.py". Now I am also asking the installer to add the Utilties.py to the path.

This is confusing, and feels like a hack. However, I can't figure out a better way to do it.

1
  • Have you considered using virtualenv? Commented Nov 6, 2011 at 18:11

1 Answer 1

3

Define a globally accessible env variable which you will use to select the version (VersionA,VersionB). Then, in Common/__init__.py put:

import whenver_you_put_your_env as envloc

if (envloc.env == VersionA)
    import VersionA.Package as Package
elif (envloc.env == VersionB)
    import VersionB.Package as Package

Now whenever you want to use Package in a file you should be able to do:

import Common.Package

and you are good to go.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.