Python 类型错误:必须是 str,而不是元组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36887861/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
TypeError: must be str, not tuple
提问by rn01
"TypeError: must be str, not tuple" Please may someone explain what this error is?
“TypeError: must be str, not tuple” 请有人解释这个错误是什么?
回答by Avión
Change receipt.write(output_to_receipt)
to receipt.write(str(output_to_receipt))
.
更改receipt.write(output_to_receipt)
为 receipt.write(str(output_to_receipt))
。
This will change output_to_receipt
which is a tuple to an string and you'll be able to write.
这将更改output_to_receipt
哪个是字符串的元组,您将能够编写。
回答by Sven Hakvoort
output_to_receipt is a tuple, so you need to convert it to a string with str(output_to_receipt)
or "".join(output_to_receipt)
for example.
output_to_receipt是一个元组,所以你需要将它与转换为字符串str(output_to_receipt)
或"".join(output_to_receipt)
为例子。