我看过许多与Python相对导入相关的问题,但我无法理解这个问题/使其正常工作。
我的目录结构如下:
Driver.py
A/
Account.py
__init__.py
B/
Test.py
__init__.py
驱动程序.py
from B import Test
账户.py
class Account:
def __init__(self):
self.money = 0
测试.py
from ..A import Account
当我尝试运行时:
python Driver.py
我遇到了错误
Traceback (most recent call last):
from B import Test
File "B/Test.py", line 1, in <module> from ..A import Account
ValueError: Attempted relative import beyond toplevel package