我正在尝试以二进制模式将一组参数保存在文本文件中。用单词[[set表示将有两个像一对的值。例如-参数=权重,值= 35。我的代码是:
with open(os.path.join(path, "parameters.txt"), "wb") as out:
for parameter, value in parameters:
out.write("{}: {}\n".format(bytearray(parameter,'utf-8'),(bytearray(value,'utf-8'))
但是主要问题是value
中的值不是同一类型。它具有int , float , string , tuple
种类型的值。所以用上面的代码我得到错误:
TypeError: a bytes-like object is required, not 'str'
是否存在以二进制模式将值保存在value
中的一般方法?即value
中所有值的单一功能注意:我正在使用python 3.5和ubuntu 16.04。我正在尝试以二进制模式将一组参数保存在文本文件中。用词集我的意思是将有两个像一对的值。例如-参数=权重,值= 35。我的代码是:with ...