【问题标题】:can someone convert this python 2 code to python 3有人可以将此python 2代码转换为python 3吗
【发布时间】:2018-11-29 12:55:27
【问题描述】:

用于保存不同标点符号的表格结构

tbl = dict.fromkeys(i for i in xrange(sys.maxunicode) if unicodedata.category(unichr(i)).startswith('P'))

【问题讨论】:

  • 请更新您的问题,提供有关您的问题的更多详细信息,添加您的代码及其输出和您想要的输出。

标签: python python-3.x


【解决方案1】:
import unicodedata
tbl = dict.fromkeys(i for i in range(sys.maxunicode) if unicodedata.category(chr(i)).startswith('P'))

在python3中没有unichr,它变成了chr。另外,没有xrange,它变成了range

【讨论】:

    【解决方案2】:

    这个呢:

    import unicodedata
    
    tbl = dict.fromkeys(i for i in range(sys.maxunicode) if unicodedata.category(chr(i)).startswith('P'))
    

    一些解释:

    Why is there no xrange function in Python3?

    Can't use unichr in Python 3.1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-31
      • 1970-01-01
      • 2019-08-29
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      • 2016-10-19
      相关资源
      最近更新 更多