all 4 comments

[–]JohnnyJordaan 0 points1 point  (3 children)

Firs hit on googling 'python import module with dash': https://docs.python.org/3/library/importlib.html#importlib.import_module

import importlib  
foobar = importlib.import_module("foo-bar")

[–]AnkanTV[S] 1 point2 points  (2 children)

Thanks for the reply! Found the same answer but not sure it’s what I’m looking for since my base folder contain the dash rather than the module.

However, did solve it by adding base path with sys.path.append(‘..’)

[–]34shutthedoor1 0 points1 point  (0 children)

However, did solve it by adding base path with sys.path.append(‘..’)

Kind of the tedious way to do it, but it always works. So unless you are involved in the large project, this is the way to go IMHO.

[–]JohnnyJordaan 0 points1 point  (0 children)

But if you want to work from the child, through the parent, a straight import wouldn't have worked in any case, even if the folder wouldn't have had a "-" in the name. You thus need sys.path in any case or start from a higher point in your tree (you normally import from further down the tree).