The Python Oracle

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

Become part of the top 3% of the developers by applying to Toptal https://topt.al/25cXVn

--

Music by Eric Matyas
https://www.soundimage.org
Track title: Peaceful Mind

--

Chapters
00:00 Question
00:33 Accepted answer (Score 165)
00:48 Answer 2 (Score 29)
01:06 Answer 3 (Score 24)
01:35 Thank you

--

Full question
https://stackoverflow.com/questions/7279...

Accepted answer links:
[relative imports]: http://www.python.org/dev/peps/pep-0328/

Answer 2 links:
[image]: https://i.stack.imgur.com/AHQmj.png

Answer 3 links:
[here]: http://docs.python.org/release/2.5.2/ref...
[here]: http://docs.python.org/tutorial/modules....

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#python #module

#avk47



ACCEPTED ANSWER

Score 169


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




ANSWER 2

Score 38


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




ANSWER 3

Score 25


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.