'Import python module from another module

I'm using Python 3.9x. As I have a code structure like:

main.py
|--moduleA
    |--A.py
|--moduleB
    |--B.py

In B.py, it imports A.py. Now I want test B.py, so I run B.py as a single python file. Then what how should import A in B.py? Note: I tried using sys.path.append('../') or from ..moduelA neither works. Please tell me what wrong was it? Thank you.



Solution 1:[1]

In this case you would import A.py like this.

import moduleA.A

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JPeck89