Python Forum
Importing packages with long names
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Importing packages with long names
#1
So I've never really sorted out a good solution to this issue, and from what I can see, there really isn't one. so I thought I'd post here as a last ditch effort to settle the issue.

The problem is this:

I am writing a series of python modules which serve as extensions / plugins for an application. The application adds modules located in the user's /Mod directory to it's environment path on startup. However, the application uses the *second* directory in the hierarchy as the top-level name for the package.

So the structure looks like this:

/Mod
  |--my_extension_first
       |--my_extension_second
            |--__init__.py
            |--my_extension_code.py
Accessing the extension directly from within the application's python console, then, would work by calling:

from my_extension_second import my_extension_code
But, if I want to access the modules from within another module (say, in another extension), I'd have to use:

from my_extension_first.my_extension_second import my_extension_code


The issue, then, is I have to maintain this structure for the sake of the application, but it forces me to pollute the import statements with extra long names.

Of course, I can't just alias the import, e.g.:

import my_extension_first.my_extension_second
my_ext = my_extension_first.my_extension_second
from my_ext import my_extension_code
So is there a way to more cleanly manage something like this? Some other way to alias a package path that I haven't discovered?
Reply


Messages In This Thread
Importing packages with long names - by joel_graff - Nov-06-2019, 01:01 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020