开发者

How to pass unicode keywords to **kwargs

I was exception the following to work.

def foo(**kwargs):
    print kwargs
foo(**{'a':'b'})
foo(**{u'a':'b'})

Traceback (most recent call last): File "", line 1, in TypeError: m() keywords must be strings

Am I doing something wrong or I should I fi开发者_Python百科x it?


Upgrade to Python 2.6.5 or later.


Upgrading wasn't an option for me so I'm calling this on dicts as needed--

def flatten_unicode_keys(d):
    for k in d:
        if isinstance(k, unicode):
            v = d[k]
            del d[k]
            d[str(k)] = v
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜