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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 18:30:33  来源:igfitidea点击:

TypeError: must be str, not tuple

python

提问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_receiptwhich 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)为例子。