Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does a . in an import statement in Python mean?

Tags:

python

module

People also ask

What are import statements in Python?

The import statement allows you to import one or more modules into your Python program, letting you make use of the definitions constructed in those modules.

What does the dot mean in from of an import?

One leading dot means the current package where the module making the import exists. Two dots means up one package level. Three dots is up two levels, etc. So if you execute from . import mod from a module in the pkg package then you will end up importing pkg.

What are the three types of import statement in Python?

There are generally three groups: standard library imports (Python's built-in modules) related third party imports (modules that are installed and do not belong to the current application) local application imports (modules that belong to the current application)

What is __ import __ in Python?

__import__() Parameters name - the name of the module you want to import. globals and locals - determines how to interpret name. fromlist - objects or submodules that should be imported by name. level - specifies whether to use absolute or relative imports.


That's the new syntax for explicit relative imports. It means import from the current package.


The dot in the module name is used for relative module import (see here and here, section 6.4.2).

You can use more than one dot, referring not to the curent package but its parent(s). This should only be used within packages, in the main module one should always use absolute module names.


default one dot in your current folder, when you want to go parent folder you can do like this, my python version 3.6.3

enter image description here