如何使选择变量的值取决于以前的选择变量选择?

2024-09-28 17:17:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用cookiecutter为Reveal.js演示文稿创建一个项目模板(仅用于上下文)

给定的template有多个themes可供选择,但并非所有模板的主题列表都相同

有没有办法根据所选的template_name修改主题列表

不是有效的json,但需要说明:

{
  "template_name": ["default", "brand"],
  "theme_name": ["default", "dark", "blue"], # if template_name == "default"
  "theme_name": ["magenta"] # if template_name == "brand"
}

任何其他建议,以实现这一点是赞赏的。谢谢


Tags: 项目name模板default主题列表ifjs
1条回答
网友
1楼 · 发布于 2024-09-28 17:17:50

您可以将“switch”元素设置为字典而不是列表

dct = {
"template_name": {"default":"theme1", 
"brand":"theme2"},
"theme1": ["default", "dark", "blue"],
"theme2": ["magenta"]
}

print(dct[dct["template_name"]["default"]])
print(dct[dct["template_name"]["brand"]])

输出:

['default', 'dark', 'blue']
['magenta']

相关问题 更多 >