我的项目树
.
├── exceptions
│ └── IvalidCreditCardException.py
├── main.py
└── validators
├── CreditCardValidatorBase.py
└── LuhnAlgorithmValidator.py
2 directories, 4 files
堆栈跟踪:
Traceback (most recent call last):
File "/home/juanjo/Documentos/Sublime-workspace/CreditCardValidator/main.py", line 3, in <module>
from validators import LuhnAlgorithmValidator
File "/home/juanjo/Documentos/Sublime-workspace/CreditCardValidator/validators/LuhnAlgorithmValidator.py", line 1, in <module>
from validators import CreditCardValidatorBase
File "/home/juanjo/Documentos/Sublime-workspace/CreditCardValidator/validators/CreditCardValidatorBase.py", line 3, in <module>
from exceptions import InvalidCreditCardException
ImportError: cannot import name 'InvalidCreditCardException' from 'exceptions' (unknown location)
导致堆栈争用的代码行
CreditCardValidatorBase:
从异常导入InvalidCreditCardException
LuhnAlgorithmValidator:
导入CreditCardValidatorBase
有没有办法让python知道正确的路径是什么?。
问题解决了,我只需要在同一目录中的文件中添加一个点。
示例:
LuhnAlgorithmValidator:
从.CreditCardValidatorBase导入CreditCardValidatorBase