Correct way to resolve import ambiguity

Robin Becker robin at jessikat.demon.co.uk
Wed May 17 11:55:56 CEST 2000


I have a package structure
A.B.f
A.B.p
A.B.d

#f.py
class F:
        pass

#p.py 
from f import F
class P(F):
        pass

#d.py
from f import *
class D:
        def b(self,A):
                assert filter(lambda x: not isinstance(x,F), A)==[], "A argument error"

if __name__=='__main__':
        def run():
                from A.B.p import P
                d = D()
                d.b([P()])
        run()

python d.py fails in d.b as it seems that using
from A.B.p import P isn't the same as
from p import P

What is the 'correct' way to resolve the ambiguity?
Should I eschew the use of sibling imports? That would seem to make maintenance/re-use harder ie
I couldn't just move the sources around.

This version of d.py runs fine 
#d.py v2
from f import *
class D:
        def b(self,A):
                assert filter(lambda x: not isinstance(x,F), A)==[], "A argument error"

if __name__=='__main__':
        def run():
                from A.B.d import D
                from A.B.p import P
                d = D()
                d.b([P()])
        run()
-confused-ly yrs- 
Robin Becker



More information about the Python-list mailing list