How to apply relative directory in python when imported from different module?
Question: Here's the problem:

In package `main.A`, there's a module `AM` and a `config.ini` file. In `AM`,
I'm using **./config.ini** to refer to this file. This just works fine.

Whereas in package `main.B`, there's another module named `BM`, which imports
`main.A.AM` module. In this time, it throws that **config.ini cannot be found
in /main/B/**

Could anyone tell me how to import this relatively located file in `Main.A`?
Thanks a lot!


Answer: The `__file__` magic variable stores the path to the file it appears in.

If you put the following line in `main.A`, it will always point to a file
residing in the same directory as `main.A`, regardless of the location
`main.A` is imported from:

    
    
    import os.path as osp 
    osp.join(osp.dirname(__file__), 'config.ini')
    

