0

I am trying to call a function that live in a sibling folder from the script that I run:

in folder-B/B.py:

def methodB():
    return "\n\nThis is methodB from Folder-B"

in folderA/A.py:

import sys
sys.path.append("..")
from folder-B.B import methodB
s = methodB()
print(s)

When calling python A.py

I get error:

File "A.py", line 3 from folder-B.B import methodB ^ SyntaxError: invalid syntax

folderA and folder-B are at the same folder level.

I know the problem comes from the dash, but I could not find any solution to keep the folder name with a dash

Any idea ?

ailauli69
  • 522
  • 6
  • 19
  • Have a look at https://stackoverflow.com/questions/8350853/how-to-import-module-when-module-name-has-a-dash-or-hyphen-in-it – script0 Oct 12 '22 at 15:53
  • 2
    Does this answer your question? [How to import module when module name has a '-' dash or hyphen in it?](https://stackoverflow.com/questions/8350853/how-to-import-module-when-module-name-has-a-dash-or-hyphen-in-it) – script0 Oct 12 '22 at 15:57
  • As an aside, the two `\n`:s at the beginning of your string look like a mistake, probably more on the design side. – tripleee Oct 12 '22 at 15:58

0 Answers0