1

以下代码来自“用于数据分析的 Python”:

from io import StringIO
import io

tag = '<a href="http://www.google.com">Google</a>'
root = objectify.parse(io.StringIO(tag).getroot())

执行代码会产生以下错误:

TypeError: initial_value must be unicode or None, not str

请帮忙!

4

1 回答 1

0

StringIO需要一个 unicode 字符串,它不是 python 2 中的默认字符串类型。替换

tag = '<a href="http://www.google.com">Google</a>'

tag = u'<a href="http://www.google.com">Google</a>'

应该管用。

于 2018-11-06T17:23:57.470 回答