0

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!

1 Answer 1

1

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')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.