name = 'foo'
zip1 = 123

message = dict([(x, locals()[x]) for x in ['name', 'zip1']])
print(message)

console:

Traceback (most recent call last):
  File "C:/Users/Administrator/PycharmProjects/YangoManagementPlatformWebTest/common/mysql.py", line 103, in <module>
    message = dict([(x, locals()[x]) for x in ['name', 'zip1']])
  File "C:/Users/Administrator/PycharmProjects/YangoManagementPlatformWebTest/common/mysql.py", line 103, in <listcomp>
    message = dict([(x, locals()[x]) for x in ['name', 'zip1']])
KeyError: 'name'

请问问题出在哪里呢?


↙↙↙阅读原文可查看相关链接,并与作者交流