如何使 PyCharm 折叠(折叠)字典构造函数 `dict()`?
How to make PyCharm collapse (fold) the dictionary constructor `dict()`?
我正在 PyCharm 工作,通过 Folding Code Elements (collapse/expand) 使我的代码更具可读性。
有没有办法折叠字典,同时仍然使用字典构造函数dict(key=value)
?
我知道 PyCharms 在使用字典文字 {key: value}
时允许代码崩溃。请参阅下面的代码示例。
我宁愿使用构造函数有两个原因:
Keys
设置为不带引号 ""
,因此更清晰;
Keys
显示的颜色不同于 values
。
万一没有办法崩溃dict构造函数:
除了 efficiency difference between dict declaration methods 之外,还有什么好的理由让我使用 dict literal 而不是 dict constructor ?
扩展码:
# literal
thisdict_1 = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
# constructor
thisdict_2 = dict(
brand="Ford",
model="Mustang",
year=1964
)
折叠代码:
# literal
thisdict_1 = {...}
# constructor
thisdict_2 = dict(
brand="Ford",
model="Mustang",
year=1964
)
python中的正常方式是
a = {'key': 'value', 'other key': 'other value'}
使用特殊评论<editor-fold desc="Description">
a = dict(
# <editor-fold desc="Description">
z=4,
d=77
# </editor-fold>
)
我正在 PyCharm 工作,通过 Folding Code Elements (collapse/expand) 使我的代码更具可读性。
有没有办法折叠字典,同时仍然使用字典构造函数dict(key=value)
?
我知道 PyCharms 在使用字典文字 {key: value}
时允许代码崩溃。请参阅下面的代码示例。
我宁愿使用构造函数有两个原因:
Keys
设置为不带引号""
,因此更清晰;Keys
显示的颜色不同于values
。
万一没有办法崩溃dict构造函数:
除了 efficiency difference between dict declaration methods 之外,还有什么好的理由让我使用 dict literal 而不是 dict constructor ?
扩展码:
# literal
thisdict_1 = {
"brand": "Ford",
"model": "Mustang",
"year": 1964
}
# constructor
thisdict_2 = dict(
brand="Ford",
model="Mustang",
year=1964
)
折叠代码:
# literal
thisdict_1 = {...}
# constructor
thisdict_2 = dict(
brand="Ford",
model="Mustang",
year=1964
)
python中的正常方式是
a = {'key': 'value', 'other key': 'other value'}
使用特殊评论<editor-fold desc="Description">
a = dict(
# <editor-fold desc="Description">
z=4,
d=77
# </editor-fold>
)