from io import StringIO f = StringIO('hello!\nHi!\nGoodBye!') while True: s = f.readline() if s == '': break print(s)
运行段时,报以下错误:
TypeError: initial_value must be unicode or None, not str
emmmm我的没有出错呢,也没看出来你哪里出问题了…… 照理说strip()只是去除空格吖……
f = StringIO(u'hello!\nHi!\nGoodBye!')
可能是python版本的问题,我用的python2.7.16. 也报了这个错,字符前加个u就行了
确实可能是版本问题,python3与python2的String语法有一些不同,详情可百度。
Sign in to make a reply
Angular2club
运行段时,报以下错误: