0

My dir looks like this

parentDir
    |__ app
    |    |__ main.py
    |
    |__ file.py

I'm in main.py and want to import a func in module file.py. I have tried to do from ../file import get_func but I get an error

SyntaxError: invalid syntax

My way does not work, any idea where I'm going wrong?

I'm using python 3.8

Shadow Walker
  • 979
  • 5
  • 27
  • 51

1 Answers1

0

You first need to remove the /. Just do from ..file import get_func

Secondly, to import from file.py the package directory parentDir must be accessible from the Python module search path (sys.path)

So you need to add it to sys.path using sys.path.append(path_of_parentDir)

pykam
  • 1,223
  • 6
  • 16
  • Nice. I’d recommend using `sys.path.insert(0, path)` as the import reads `sys.path` top to bottom, so to speak. – S3DEV Mar 23 '21 at 09:30