I'm not trying to support python 2 and python 3.

I just want to use python 3. The issue of using absolute imports seems like a hack. What happens if a user or I need to change the path. Should I have to change the all the imports?


I believe I am going to use absolute paths in the end (all I need is a good editor to make the changes) but I was hoping to find something that would work in a more universal way.


Johnf


On 05/31/2017 12:03 PM, Peter Otten wrote:
john wrote:

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
modules/files?
That is likely to create a big mess; you may end up with two versions of the
same module, with puzzling results.

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to