0

I have a package written in Python 2, and I am trying to retrofit to work with Python 3. It's been painful to say the least. I have an issue using the future absolute_import part of the code.

This works in Python 2 but not Python 3, so I'm hoping someone can point out my issue.

The package structure is:

fusion -> __init__.py agol -> featureservice.py -> layer.py 

The fusion init is defined as:

from __future__ import absolute_import from . import agol 

The agol sub package is defined as:

from __future__ import absolute_import from . import featureservice from . import layer 

The featureservice.py has this import, where the issue is: from . import layer The layer.py has a similar import: from . import featureservice

They each can reference each other where the layer could be a child of feature service. But I get this import issue, what is the proper way to import this module into each py file?

Thank you

1
  • What do you mean by " get this import issue"? Is it an exception? Can you paste the exception here? Thanks! Commented Nov 17, 2015 at 19:05

1 Answer 1

2

Circular relative imports do not work in Python 3.

Circular imports are considered a bad practice because you've tightly coupled both modules to each other. You may want to consider why you need to import featureservice into layer and layer into featureservice.

Maybe there are some functions in each that should be in yet another module that is depended upon by both? Or maybe instead of further splitting these modules, you should merge them together?

Related reading:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.