I have a Python class called “ClassA” and another Python class which is supposed to import ClassA which is “ClassB”. The directory structure is as follows:
MainDir
../Dir
..../DirA/ClassA
..../DirB/ClassB
How would I use sys.path so that ClassB can use ClassA?
You really should be using packages. Then MainDir is placed at a point in the file system on sys.path (e.g. …/site-packages), then you can say in ClassB:
You just have to place files named
__init__.pyin each directory to make it a package hierarchy.