gpt4 book ai didi

python - 如何检索 `__all__` 的值

转载 作者:太空宇宙 更新时间:2023-11-04 02:26:51 25 4
gpt4 key购买 nike

django/django/db/models/fields/__init__.py有变量:

__all__ = [
'AutoField', 'BLANK_CHOICE_DASH', 'BigAutoField', 'BigIntegerField',
'BinaryField', 'BooleanField', 'CharField', 'CommaSeparatedIntegerField',
'DateField', 'DateTimeField', 'DecimalField', 'DurationField',
'EmailField', 'Empty', 'Field', 'FieldDoesNotExist', 'FilePathField',
'FloatField', 'GenericIPAddressField', 'IPAddressField', 'IntegerField',
'NOT_PROVIDED', 'NullBooleanField', 'PositiveIntegerField',
'PositiveSmallIntegerField', 'SlugField', 'SmallIntegerField', 'TextField',
'TimeField', 'URLField', 'UUIDField',
]

Django 如何获取变量__all__?是吗fields.__init__.__all__ 还是 fields.__all__

最佳答案

Django 不直接使用该变量,而是由 Python import 语句使用。如果您想访问该值,您可以执行以下操作:

from django.db.models import fields
print(fields.__all__)

参见 this question寻求解释。

关于python - 如何检索 `__all__` 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50165717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com