【问题标题】:TypeError: ljust() argument 2 must be char, not unicodeTypeError: ljust() 参数 2 必须是 char,而不是 unicode
【发布时间】:2020-09-03 21:11:50
【问题描述】:

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

ljust() argument 2 must be char, not unicode

方法是link to the file on GH:

    @classmethod
    def from_token(cls, token):
        """Creates a CellId from a hex encoded cell id string, called a token.
        :param str token:
            A hex representation of the cell id. If the input is shorter than
            16 characters, zeros are appended on the right.
        """
        return cls(int(token.ljust(16, '0'), 16))

该文件似乎是 ASCII 编码的,所以我正在为为什么会看到这个而摸不着头脑

【问题讨论】:

    标签: python python-2.7 python-unicode s2


    【解决方案1】:

    文件在顶部导入 unicode_literals:

    from __future__ import print_function, unicode_literals, division
    

    因此'0'是一个unicode字符串&'token'参数需要是unicode才能匹配

    【讨论】:

      猜你喜欢
      • 2019-03-15
      • 1970-01-01
      • 1970-01-01
      • 2017-01-28
      • 2021-05-17
      • 2016-11-18
      • 2017-01-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多