我有一个函数(如下所示),它使用unicode函数,但我收到了一个"NameError: name‘unicode未定义“,这使我相信我需要导入unicode,所以我尝试了:
pip install unicode然后:
from unicode import unicode我得到了一个错误:
ModuleNotFoundError: No module named 'unicode'调用unicode函数的代码是:
def makelist(table):
result = []
allrows = table.findAll('tr')
for row in allrows:
result.append([])
allcols = row.findAll('td')
for col in allcols:
thestrings = [unicode(s) for s in col.findAll(text=True)]
thetext = ''.join(thestrings)
result[-1].append(thetext)
return result我做错什么了?
发布于 2022-10-11 21:44:52
我怀疑代码片段必须是用于Python2的,unicode()是一个内置函数,可以在没有导入的情况下使用。在Python 3中,默认情况下文字字符串是Unicode,因此不需要显式转换它们。
https://stackoverflow.com/questions/74033304
复制相似问题