【发布时间】:2020-02-26 11:59:10
【问题描述】:
我有一个 Python 2 代码库,我正在迁移到 Python 3。旧代码库使用
import string
foo = string.replace(s, old, new)
foo = string.strip(s)
foo = string.find(s, sub, start, end)
我用 2to3 移动了它,但这给出了一个错误。我的猜测是我必须用
替换上面的foo = s.replace(old, new)
foo = s.strip()
foo = s.find(sub, start, end)
我查看了文档:
它们看起来完全一样。为什么这些函数首先出现在 string 模块中?这是 Python 2.7 之前的变化吗?是否可能存在性能差异或某些特殊情况的不同处理方式?
【问题讨论】:
标签: python python-3.x python-2.7 python-2to3