The method error reported in _ _ init__.py introduced by python does not exist.

< H1 > question < / H1 >

introduce the contents of _ _ init__.py under the current directory into the script article.py to report an error ImportError: cannot import name "fake"

< H1 > path < / H1 >

test/

__init__.py
article.py

file _ _ init__.py

-sharp -*- coding:utf-8 -*-
def fake():
    print("A")

File article.py

-sharp -*- coding:utf-8 -*-
from . import fake
print(fake)

execute python article.py error prompt:

Traceback (most recent call last):
  File "article.py", line 2, in <module>
    from . import fake
ImportError: cannot import name "fake"

how to introduce the contents of _ _ init__.py in article.py

Apr.02,2021

try this

   

I hope it will be helpful to you.

Menu