I'd like Python to look into a package first for imports -
i might @ odds python's way of thinking here, me, when comes package (or project folder system), contents of package should always more important anything outside of package, including pythonpath
.
take hierarchy example:
somewhere/ foo/ __init__.py bar/ __init__.py foo/ __init__.py
if somewhere
in pythonpath
, , nothing else here is, , in somewhere/bar/__init__.py
simple import foo
, feel bar
should import child, somewhere/bar/foo
, not total stranger, somewhere/foo
path variable. path should go if can't find right inside own system.
in tests, though, seems pythonpath
trumps direct descendants, shame, because it's less powerful, less flexible system, , doesn't honor dag nature of hierarchies. children come first, not siblings, , not ancestors or complete, non-relations. however, when remove pythonpath
, uses foo
inside bar
.
am doing wrong, or python work way? there can make work way think should? if remove somewhere/bar/foo
, then can in path, if explicitly put foo
in bar
, should use that, instance variable override class variable.
pep 238 absolute , relatve imports.
as understood, from . import bar
import right thing. reading pep understanding different ways of importing modules.
they point out, absolut imports default, because can used everything:
import foo import bar.foo import sys
in contrast to:
import ..foo import .foo import sys #absolute
Comments
Post a Comment