TypeError: a bytes-like object is required, not 'str' when writing to a file in Python3

前端 未结 9 2037
Happy的楠姐
Happy的楠姐 2020-11-22 04:58

I\'ve very recently migrated to Py 3.5. This code was working properly in Python 2.7:

with open(fname, \'rb\') as f:
    lines = [x.strip() for x in f.readli         


        
9条回答
  •  渐次进展
    2020-11-22 05:25

    You can encode your string by using .encode()

    Example:

    'Hello World'.encode()
    

提交回复
热议问题