Relative Import Issues

EDIT: Is from __future__ import absolute_importit available in IronPython? I just realized that all I use is just python, the project as a whole is in IronPython.

I am trying to use relative imports (instead of adding to sys.path). Here is my directory structure:

-src
  |
  -runners
    |
    -__init__.py
    -clippyRunner.py
  |
  -__init__.py
  -clippy.py
  -irondb.py
  -ironxl.py

now, in clippyRunner.py, I want to import a clip, which, as you can see, is in the parent directory src. so i did this:

from __future__ import absolute_import
from ...src import clippy

but this gives me this error:

ValueError: Attempted relative import in non-package

I also tried

from ..src import clippy

with the same results.

what am i doing wrong here?

EDIT: I also tried import ..clippy which just gives me:SyntaxError: unexpected token '.'

+3
source share
2 answers

, , , IronPython , , .

'__main__' 'src.runners.clippyRunner' __name__, , /src/runners/clippyRunner.py . , , Python , .

CPython , python -m src.runners.clippyRunner , src, , .

, IronPython (CPython , PEP 366 2.6)

+1

:

 from .. import clippy
+1

Source: https://habr.com/ru/post/1794751/


All Articles