This topic created in 2461 days ago, the information mentioned may be changed or developed.
from collections import OrderedDict
dict = OrderedDict()
def main():
list = [['a', 1], ['b', 2], ['c', 3]]
global dict = OrderedDict(list)
最后一句报语法错误,请大佬指点一下原因...
5 replies • 2019-08-31 08:15:54 +08:00
 |
|
1
banxi1988 Aug 31, 2019
1. 错误提示很明显. `dict` 重定义了. 你可以看 `global` 关键词的说明: > Names listed in a global statement must not be used in the same code block textually preceding that global statement.
2. dict 是内置的类名,用来作变量名,习惯不好.
3. 发贴不注意缩进, 差评.
|
 |
|
2
echo1937 Aug 31, 2019 1
首先,使用 global 时,先声明,再赋值: global dict dict = OrderedDict(list)
其次,dict 是 build-in name,最好不要拿来当变量名
|
 |
|
5
swulling Aug 31, 2019 via iPhone
原则上别用全局变量
|