由于'wb'模式是二进制输入,所以要在''前面加上b才能正常写入.不然会有报错.
TypeError: a bytes-like object is required, not 'str'
环境 python 3.6
f = open('test.txt', 'wb')
for i in range(3):
f.write(b'hello python
')
f.close()
由于'wb'模式是二进制输入,所以要在''前面加上b才能正常写入.不然会有报错.
TypeError: a bytes-like object is required, not 'str'
环境 python 3.6
f = open('test.txt', 'wb')
for i in range(3):
f.write(b'hello python
')
f.close()