python import from sibling directory

Solutions on MaxInterview for python import from sibling directory by the best coders in the world

showing results for - "python import from sibling directory"
Lana
16 Oct 2018
1# Directory Structure
2parent_dir/
3    foo_dir/
4        foo.py
5    bar_dir/
6        bar.py
7      
8# bar.py
9def foobar():
10    print("foobar")
11      
12# foo.py       
13import sys
14import os
15sys.path.append(os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'bar_dir')))
16from bar import foobar
17foobar()
18
19