元组不会转换为字符串

2024-06-28 19:59:31 发布

您现在位置:Python中文网/ 问答频道 /正文

好吧,这真让我头疼

pevCommand = commands.getstatusoutput('pev ' + fileName)
pevString = "".join(map(str, pevCommand))

之后:

<hr />
<h3 style="color:blue;">
      <strong>--Pev Output--:  </strong></h3>
        <p>'''+pevString+'''</p>
<hr />

获取以下错误:

TypeError: cannot concatenate 'str' and 'tuple' objects

我希望pevCommand的输出是一个字符串,我不确定map是否正确,并尝试了一系列其他方法,如下面列出的方法:

TypeError: sequence item 0: expected string, int found


Tags: 方法mapstylehrfilenameh3commandsstrong
1条回答
网友
1楼 · 发布于 2024-06-28 19:59:31

假设问题是.join()调用,看看您是如何链接到某个内容的,该内容提到列表序列中有整数,并且以某种方式与列表相关。。这将解决以下问题:

pevString = "".join((str(x) for x in pevCommand))

相关问题 更多 >