python - Plotly Dash children= clause
问题描述
I'm using dash in Python and have seen the "children= " clause. However in most cases I can remove it and the code runs just the same! Nowhere in the documentation I can find the reason for including it.
From the documentation you get:
The children property is special. By convention, it's always the first attribute which means that you can omit it:
So what's the purpose of children= in the code if you can decide to not use it and everything runs fine?
解决方案
有人可能想要包含它有几个可能的原因。来自 Python 之禅:
显式优于隐式。
另一个原因可能是您的组件具有要分配的多个不同属性,并且它更适合具有以下内容的样式:
html.Div(
children='text',
id='my-div',
style=dict(color='green')
)
这也有助于语法突出显示,然后使子项与其他属性的颜色相匹配。否则,它可能看起来不一样,并且可能在一大段代码中变得更难看到。
使用 kwarg 还允许您将children
属性作为第一个属性以外的东西传递。我不确定是否有必要这样做,但只有通过显式分配才有可能。
推荐阅读
- java - java: 此处不允许使用 var
- c++ - 从 c++ 共享库中导出函数:在 Windows 上正常,在 Linux 上失败
- ruby - 从 XCode plist 读取的 Ruby shell 脚本
- c# - Specflow - 测试夹具 Account.AddBankAccountFeature BoDi.ObjectContainerException 的 TearDown 失败
- c# - C# 实体框架使用 SQL 选项/提示
- python - AttributeError:“三角形”对象没有属性“number_of_sides”
- php - [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]在 Laravel 中使用 model::with 时转换失败
- python - System of Equations in numpy
- spring-boot - Difference between spring-cloud-stream-binder-kafka and spring-cloud-starter-stream-kafka
- mysql - How to disable the "secure-file-priv" on macOS?