python: TypeError: can't write str to text stream

后端 未结 5 1844
灰色年华
灰色年华 2020-12-15 05:10

I must be doing something obviously wrong here. But what is it, and how do I fix?

Python 2.6.5 (r265:79096, Mar 19 2010, 21:48:26) [MSC v.1500 32 bit (Intel)         


        
5条回答
  •  有刺的猬
    2020-12-15 05:19

    Have you tried writing a Unicode string, instead of just a str? I.e.,

    fq.write(u"bingo")
    

    I'm on Mac OS X, but when I tried to write a str, I got the error

    TypeError: must be unicode, not str

    Writing a Unicode string worked, though.

提交回复
热议问题