2

This is a follow up to "How to import a Python class that is in a directory above?", which gives how to import a file from the parent directory:

from .. import module

I to get a specific function from a file in the directory above.

This is my attempt: There is a file in the higher directory called topLevel.py which has a function called test_function.

from .. import topLevel
from topLevel import test_function

This is the error message:

ValueError: attempted relative import beyond top-level package
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
SantoshGupta7
  • 5,607
  • 14
  • 58
  • 116
  • Please provide the entire error message. – AMC Mar 20 '20 at 22:39
  • Does this answer your question? [beyond top level package error in relative import](https://stackoverflow.com/questions/30669474/beyond-top-level-package-error-in-relative-import) – AMC Mar 20 '20 at 22:40

1 Answers1

0
import sys 
sys.path.insert(0, "./../" )
from topLevel import test_function

test_function()
sin tribu
  • 1,148
  • 1
  • 6
  • 14