无法在类似字节的对象上使用字符串模式

时间:2019-08-26 09:32:47

标签: python

我有问题。

此功能在我的/usr/local/lib/python3.7/re.py

def search(pattern, string, flags=0):
    """Scan through string looking for a match to the pattern, returning
    a Match object, or None if no match was found."""
    return _compile(pattern, flags).search(string)

我在此行中调用此函数:

total = int(re.sub("[',\. ]", "", re.search("(([0-9]+[',\. ])*[0-9]+)", totalText).group(1)))

但是我得到这个错误:

return _compile(pattern, flags).search(string)
TypeError: cannot use a string pattern on a bytes-like object

我该如何解决?

1 个答案:

答案 0 :(得分:1)

totalText的类型不是您所期望的。尝试用totalText.decode()代替它。