[Tutor] sub-modules and python3
__peter__ at web.de
Wed May 31 15:03:42 EDT 2017
> Hi folks,
> In the past I used a simple "import filename" for sub-modules in python
> 2. With python 3 I have run into errors reported (file not found) using
> python 2 import statements. But I'm not asking how to correct the
> import as I am able to change the way I write the import as a work
> around - but I'm importing all the files at once. What I want to know
> is what is the best practice for my situation.
> Is there a simple way using python 3 to emulate python 2 imports?
> Is there a standard python 3 import tool for sub-modules (files)?
> Any help or thoughts on the matter is welcome.
Are you talking about intra-package imports? Rather than having Python 3
emulate Python 2 you could switch on absolute imports in py2:
from __future__ import absolute_import # must be at the beginning
# of the module, then
import alpha # import toplevel alpha.py
from . import alpha # import sibling in current package
> Is it acceptable to add/change the os path to allow my app to find the
That is likely to create a big mess; you may end up with two versions of the
same module, with puzzling results.
More information about the Tutor