Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python cannot import, unknown location

I've three file in pycharm project like,

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

Both parser.py and test.py have the same code.

def test():
    print('test')

But I can only execute main.py with below and it outputs test

from test import test

test()

While when I execute main.py with below,

from parser import test

test()

it output's

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

Here is the project architecture. I can use Ctrl + Left Click to jump to the test function in main.py in both case.

enter image description here

like image 596
LF00 Avatar asked Oct 28 '19 04:10

LF00


1 Answers

It's because parser is a library in python. Use another name for parser file.

like image 150
Sasan Yasari Avatar answered Sep 30 '22 15:09

Sasan Yasari