0

I am on Python 2.7. I've been using imp to import a module from a filepath, everything works fine but one little detail. The file I am importing belongs to another library, let's call its package "Users" and the library "School", then the file I am importing is School.Users.Common.py. The first line of Common.py imports a file from the same package (const.py):

from School.Users import const

When I use imp to import this file in my other project, School.Users module doesn't exist, so the interpreter doesn't know where to get const.py file and it throws an exception. Is there a way I can workaround this, e.g. creating a package at runtime containing the const module (and eventually other package files) and add it in the sys.modules variable, so when the interpreter runs "from School.Users import const" it's tricked to look in a specific place where the module would exist? (Eventually after being imported using imp).

Or, another idea, is there a way to use imp to load a full package and not just a single module?

Thanks.

Kotsuki
  • 61
  • 1
  • 3

1 Answers1

0

use like this

from School.Users.const import *

for importing the Const.py

check this for relative import Importing from a relative path in Python

Vignesh
  • 1,553
  • 1
  • 10
  • 25