What meaning is 'from . import'

Chris Angelico rosuav at gmail.com
Thu Jan 7 12:00:06 EST 2016


On Fri, Jan 8, 2016 at 3:50 AM, Robert <rxjwg98 at gmail.com> wrote:
> Hi,
>
> I see the following code. After searching around, I still don't know the
> meaning of '.'. Could you tell me that ? Thanks,
>
>
>
>
>
> from . import _hmmc
> from .utils import normalize

That's called a package-relative import.

https://www.python.org/dev/peps/pep-0328/

If you create a package called (let's be really creative here)
"package", an external script could do this:

from package import _hmmc
from package.utils import normalize

Within the package, you can say "from myself import stuff". It's
exactly the same thing, only it doesn't repeat the package name. If
you think of a package as a directory (which it often will be anyway),
the dot is similar to the common notation for "current directory".

ChrisA



More information about the Python-list mailing list