module - How to import a Python class that is in a directory above? -
I want to inherit a file from that file which is currently in the directory above.
Is it possible to import this file relatively?
Inside a package hierarchy, use two points, as the Doctor says:
When you specify the module for importing, you do not have to specify the full name of the module. When a module or package is included in another package, it is possible to import a relative within the same package without mentioning the package name. By using the leading points in the module or package specified by
you can specify how high the current package range is in order without specifying the exact name. A leading dot means the current package where the importing module is present. Two points mean a package level Three points are two levels, etc. If you execute with
import mod
from a module in thepkg
package, then you will stop importingpkg.mod
. If you executewith
with pkg.subpkg1
you will importpkg.subpkg2.mod
. The specification contained for the relative import.
relates to full / relative import.
Comments
Post a Comment