Python无法导入,位置未知

LF00

我在pycharm项目中有三个文件,

project
├── main.py 
├── parser.py
└── test.py

parser.py和test.py都具有相同的代码。

def test():
    print('test')

但是我只能在下面执行main.py并输出 test

from test import test

test()

当我在下面执行main.py时,

from parser import test

test()

它输出的

Traceback (most recent call last):
  File "C:/Users/lf/Desktop/jye_parser/main.py", line 1, in <module>
    from parser import test
ImportError: cannot import name 'test' from 'parser' (unknown location)

Process finished with exit code 1

这是项目架构。在两种情况下,我都可以使用Ctrl+Left Click跳转到testmain.py中函数。

在此处输入图片说明

萨珊·亚萨里(Sasan yasari)

这是因为解析器是python中的库。为解析器文件使用其他名称。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章