Answers for "python import from sibling directory"

1

python import from sibling directory

# Directory Structure
parent_dir/
    foo_dir/
        foo.py
    bar_dir/
        bar.py
      
# bar.py
def foobar():
    print("foobar")
      
# foo.py       
import sys
import os
sys.path.append(os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'bar_dir')))
from bar import foobar
foobar()
Posted by: Guest on July-28-2021

Code answers related to "python import from sibling directory"

Python Answers by Framework

Browse Popular Code Answers by Language