有人可以用 Python 解释 __all__ 吗? [英] Can someone explain __all__ in Python?

查看:37
本文介绍了有人可以用 Python 解释 __all__ 吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have been using Python more and more, and I keep seeing the variable __all__ set in different __init__.py files. Can someone explain what this does?

推荐答案

它是该模块的公共对象列表,由 import * 解释.它覆盖了隐藏以下划线开头的所有内容的默认设置.

It's a list of public objects of that module, as interpreted by import *. It overrides the default of hiding everything that begins with an underscore.

这篇关于有人可以用 Python 解释 __all__ 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆