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

code base 5000
  • 3,812
  • 13
  • 44
  • 73

1 Answers1

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:

Community
  • 1
  • 1
Trey Hunner
  • 10,975
  • 4
  • 55
  • 114