Discuss / Python / StringIO逐行打印的例子在2.x下运行会提示initial value 必须是unicode或者None

StringIO逐行打印的例子在2.x下运行会提示initial value 必须是unicode或者None

Topic source

lubang03

#1 Created at ... [Delete] [Delete and Lock User]

第二行就执行不了

若月汐年

#2 Created at ... [Delete] [Delete and Lock User]

你找到原因了么,我和你的是一样 from io import StringIO

f = StringIO() f.write('hello') print(f.getvalue())

Traceback (most recent call last): File "Z:/IOexample.py", line 6, in <module> f.write() TypeError: write() takes exactly one argument (0 given)

<code>f.write(u'hello')</code>

<code>f.write(u'hello')</code>


  • 1

Reply