Python报“TypeError: a bytes-like object is required, not ‘str’ ”解决办法

2023-10-26

import os,sys

#打开文件
fd = os.open('foo.txt',os.O_RDWR|os.O_CREAT)

str = 'this is fujieace.com test'

str = str.encode()   //添加转换方法   encode()即可

#写入字符串
os.write(fd,str)

#关闭文件
os.close(fd)

print('关闭文件成功!')
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Python报“TypeError: a bytes-like object is required, not ‘str’ ”解决办法 的相关文章

随机推荐