【发布时间】:2012-11-08 14:58:09
【问题描述】:
我知道 Python 字典键中可以有空格,但这被认为是糟糕的编程吗?我在 PEP 中找不到任何关于此的内容。
编辑澄清:
在我正在做的一个项目中,我正在研究解析来自 Apache 的mod_status 的记分牌输出(参见下面的示例输出。)我只是想找出最佳实践。我应该这样结束吗:
workers = {'W': 1,
'_': 9,
...}
或者这个:
workers = {'Sending Reply': 1,
'Waiting for Connection': 9,
...}
示例mod_status 输出:
_....___W____._.................................................
................................................................
................................................................
................................................................
Scoreboard Key:
"_" Waiting for Connection, "S" Starting up, "R" Reading Request,
"W" Sending Reply, "K" Keepalive (read), "D" DNS Lookup,
"C" Closing connection, "L" Logging, "G" Gracefully finishing,
"I" Idle cleanup of worker, "." Open slot with no current process
【问题讨论】:
-
它只是一个容器 - 任何可散列的东西都是有效的 - 为什么 PEP8 会关注特定值?
标签: python dictionary key