'str' does not support the buffer interface Python3 from Python2

后端 未结 2 1408
鱼传尺愫
鱼传尺愫 2020-12-10 04:29

Hi have this two funtions in Py2 works fine but it doesn´t works on Py3

def encoding(text, codes):
    binary = \'\'
    f = open(\'bytes.bin\', \'wb\')
             


        
2条回答
  •  -上瘾入骨i
    2020-12-10 04:48

    The fix was simple for me

    Use

    f = open('bytes.bin', 'w')
    

    instead of

    f = open('bytes.bin', 'wb') 
    

    In python 3 'w' is what you need, not 'wb'.

提交回复
热议问题