Python2.6字典的键替unicode,解包时报错

Python2.6字典的键为unicode,解包时报错

 

把代码放到局域网服务器,原本在本地运行正常的代码在局域网服务器上却报错,Google一下相关错误,原来是Python2.6的一个Bug。

Python2.6下,如果有dict的key是unicode,当把它解包传给函数作为参数时,会报错

 

 

from datetime import *
date(1,2,**{u'day':10,u'x':20})

TypeError: date() keywords must be strings

 在Python2.7下不会有问题。

参看  http://bugs.python.org/issue2646