gpt4 book ai didi

python - 为什么 Django 使用元组进行设置而不是列表?

转载 作者:IT老高 更新时间:2023-10-28 21:02:16 26 4
gpt4 key购买 nike

引用 this answer :

Apart from tuples being immutable there is also a semantic distinction that should guide their usage. Tuples are heterogeneous data structures (i.e., their entries have different meanings), while lists are homogeneous sequences. Tuples have structure, lists have order.

这对我来说很有意义。但是为什么 Django 使用元组而不是列表进行设置呢?示例:

INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
)

这(以及所有其他设置)在语义上不是列表的完美案例吗?

最佳答案

这在 Django 1.9 中有所改变:

Default settings that were tuples are now lists

The default settings in django.conf.global_settings were a combination of lists and tuples. All settings that were formerly tuples are now lists.

https://docs.djangoproject.com/en/1.9/releases/1.9/#default-settings-that-were-tuples-are-now-lists

关于python - 为什么 Django 使用元组进行设置而不是列表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12349784/

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