我正在使用PyCharm,为了提高代码的可读性,我使用了折叠码元件 (折叠/展开)特性。
是否存在折叠字典的方法,同时仍然使用dict构造函数dict(key=value)
我知道PyCharm允许在使用dict文字{key: value}时折叠代码(参见下面的代码示例)。
我宁愿使用构造函数有两个原因:
Keys被设置为没有引号"",因此更干净;Keys显示的颜色与values不同。如果没有办法折叠dict构造函数,那么除了dict声明方法的效率差异之外,是否有一个很好的理由来解释为什么要使用dict文本而不是dict构造函数?
扩展代码:
# 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
)发布于 2018-12-22 15:21:33
使用特殊注释<editor-fold desc="Description">
a = dict(
# <editor-fold desc="Description">
z=4,
d=77
# </editor-fold>
)发布于 2018-12-22 15:07:47
python的正常方式是
a = {'key': 'value', 'other key': 'other value'}https://stackoverflow.com/questions/53896645
复制相似问题