Skip to content Skip to sidebar Skip to footer

Python To Specify Which Module To Import From If There Are Duplicate Module Names?

Related to: Import a module from a relative path dirA/ A.py B.py dirB/ B.py A.py import B # do blah I want A to import B. How do i specify A to import B from dirB in

Solution 1:

I think what you're asking for is how to load a module directly from a directory.

importimpmoduleB= imp.load_source('moduleB', '/ModuleBPath/B.py')
moduleB.MyClass()

Solution 2:

u can use like below :-

fromA import BfromB import B as B1

and continue to use.

Solution 3:

You could try such variant:

from ..dirB import B

Post a Comment for "Python To Specify Which Module To Import From If There Are Duplicate Module Names?"