3
我在导入相同程序包中的类时遇到了问题,它似乎不是循环依赖项问题。所以我现在很困惑。ImportError:无法导入名称(不是循环依赖项)
my-project/
lexer.py
exceptions.py
我exceptions.py
声明的异常,并希望利用它在lexer.py
:
exceptions.py:
class LexError(Exception):
def __init__(self, message, line):
self.message = message
self.line = line
和lexer.py:
import re
import sys
from exceptions import LexError
...
它不应该是循环依赖,因为lexer.py
是只有文件有import
。
谢谢!
你可以尝试重命名'exceptions.py'到别的东西,看看是否有帮助吗? – Adeeb
@Adeeb它的作品!但为什么?在这个[回购](https://github.com/miguelgrinberg/flasky/search?utf8=%E2%9C%93&q=ValidationError)中,你可以看到exceptions.py应该会导致一个ImportError !? – Rundis
@Adeeb这[回购](https://github.com/miguelgrinberg/flasky/search?utf8=%E2%9C%93&q=ValidationError)来自[Flask Web Development]一书(http://shop.oreilly .com/product/0636920031116.do) – Rundis