[英]Very simple importing is not working in python
main.py:主要.py:
import second
from second import *
print(second.a)
second.py:第二个.py:
a = "testA"
b = "testB"
Error:错误:
AttributeError: module 'second' has no attribute 'a'
Importing wasn't working on a more complex program.导入不适用于更复杂的程序。 Tried to test it simply and it's not working.
试图简单地测试它,但它不起作用。
Inside the project folder, there are the other .py
files as well as a __pycache__
folder在项目文件夹中,还有其他
.py
文件以及__pycache__
文件夹
Doing ↓ doesn't work either:做 ↓ 也不起作用:
from second import a, b
Your code works for me as well.你的代码也适用于我。 I think it maybe caused by your .pyc file which you run your code before.
我认为这可能是由您之前运行代码的 .pyc 文件引起的。
Delete .pyc file in your package and rerun your code.删除包中的 .pyc 文件并重新运行代码。
Or you can try running your code in a new environment.或者您可以尝试在新环境中运行您的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.