[Tutor] sub-modules and python3
ben+python at benfinney.id.au
Wed May 31 21:46:54 EDT 2017
johnf <johnf at jfcomputer.com> writes:
> I just want to use python 3. The issue of using absolute imports seems
> like a hack.
Absolute import is what Python 3 does when you ask to import a module
without leading dots.
Relative import is what Python 3 does when you ask to import a module
with leading dots.
If you want to use Python 3 – and I am glad you do! – that's the import
behaviour you'll get.
> What happens if a user or I need to change the path. Should I have to
> change the all the imports?
You are asking for relative imports, and yes relative import is what you
should use to avoid having to care where the code is installed.
In Python 3, to import from a relative path, use leading dots (because a
path without leading dots is absolute). This explicitly tells Python
that the path is relative to the module where the import statement is.
You would have learned this when you worked through the Python 3
tutorial <URL:>https://docs.python.org/3/tutorial/modules.html>. Maybe
it's time to work through again?
\ “About four years ago, I was — no, it was yesterday.” —Steven |
`\ Wright |
More information about the Tutor