Search code examples
pythonpython-3.xpython-importrelative-path

Relative vs explicit import upgrading from python 2


I don't understand the following from pep-0404

In Python 3, implicit relative imports within packages are no longer available - only absolute imports and explicit relative imports are supported. In addition, star imports (e.g. from x import *) are only permitted in module level code. What is a relative import?

I have lines that import like this From . Import " something"

Why is it just a dot?


Solution

  • According to the documentation, I need to add the package name in front of the (.). So an (import .module) should be (import filename.module). Statements like (from . import something) can change to (import filename.module.something as something)