I was trying to understand how packages like Numpy/Pandas makes its imports, and Numpy seems to call from its core package. For example, in numpy/linalg/linalg.py
, it makes an import
from numpy.core import (
array, asarray, zeros, empty, empty_like, intc, single, double,
csingle, cdouble, inexact, complexfloating, newaxis, all, Inf, dot,
add, multiply, sqrt, fastCopyAndTranspose, sum, isfinite,
finfo, errstate, geterrobj, moveaxis, amin, amax, product, abs,
atleast_2d, intp, asanyarray, object_, matmul,
swapaxes, divide, count_nonzero, isnan, sign
)
in order to make its basic operations. However, the folder structure is
numpy
> core
> __init__.py
> _asarray.py
> _dtype.py
...
> linalg
> __init__.py
> linalg.py <--- Looking at this one
...
> fft
> __init__.py
> helper.py
> _pocketfft.py <--- Same thing happens here
...
But since core
is a sister directory to linalg
, how is it that numpy/linalg/linalg.py
is able to use from numpy.core import ...
since it wouldn't be able to capture anything from a parent directory?
My problem is that I have a folder structure:
pkg
> banana
> __init__.py
> banana.py
> fruit
> __init__.py
> fruit.py
where
# pkg/fruit/__init__.py
from .fruit import func1
# pkg/banana/__init__.py
from .banana import *
from ..fruit import func1 # This won't work
and I'd like to have func1
be used in the banana
package