Python 3.1.3 Win 7: csv writerow Error “must be bytes or buffer, not str”

后端 未结 3 1944
野趣味
野趣味 2021-01-14 02:37

Got a simple script which worked perfectly under Python 2.7.1 at my Win xp machine. Now got a win 7 machine with python 3.1.3.

The code is:

owriter.w         


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-14 03:05

    Change to str.encode("ascii").

    The point is that Python 2.x had somewhat mixed usage of str type for storing byte buffers and for storing character strings. Now in Python 3.x we have proper Unicode support and byte buffers are now separate type. You can convert between them using str.encode() and bytes.decode() specifying each time a character encoding as parameter.

提交回复
热议问题