相关疑难解决方法(0)

有人可以在Python中解释__all__吗?

我越来越多地使用Python,并且我一直__all__在不同的__init__.py文件中看到变量集.有人可以解释这是做什么的吗?

python syntax namespaces

873
推荐指数
10
解决办法
26万
查看次数

导入__init__.py中的文件

我将我的test.py文件拆分成多个文件,比如

app
app\models.py
app\views.py
app\tests
app\tests__init__.py
app\tests\test_bananas.py
app\tests\test_apples.py
Run Code Online (Sandbox Code Playgroud)

和导入如下__init__.py:

from test_bananas import BananasTest
from test_apples import ApplesTest
Run Code Online (Sandbox Code Playgroud)

pyflakes给我错误

modules/app/tests/__init__.py:5: [E] PYFLAKES:'BananasTest' imported but unused
modules/app/tests/__init__.py:5: [E] PYFLAKES:'ApplesTest' imported but unused
Run Code Online (Sandbox Code Playgroud)

试过这个也

from test_bananas import *
from test_apples import *
Run Code Online (Sandbox Code Playgroud)

再次pyflakes给我错误

PYFLAKES:'from test_bananas import *' used; unable to detect undefined names
PYFLAKES:'from test_apples import *' used; unable to detect undefined names
Run Code Online (Sandbox Code Playgroud)

python django import

7
推荐指数
5
解决办法
6709
查看次数

标签 统计

python ×2

django ×1

import ×1

namespaces ×1

syntax ×1