TypeError:ljust参数2必须是char,而不是unicode

问题描述

this location的python2.7中使用s2sphere库时,出现以下错误

C = {k: A.get(k,['0']) + B.get(k,['0']) for k in A.keys() | B.keys()}

方法link to the file on GH

ljust() argument 2 must be char,not unicode

文件似乎是ASCII编码的,所以我想知道为什么会出现这种情况

解决方法

文件在顶部导入unicode_literals:

from __future__ import print_function,unicode_literals,division

因此,“ 0”是一个unicode字符串,并且“ token”参数必须是unicode才能匹配