我使用的代码如下:
if len(areUnusedParams) > 0:
tkMessageBox.showinfo('Error!','The following parameters are unchanged throughout the C-files and are also not present in parameter.txt:\n')现在,我希望在显示areUnusedParams时发布MessageBox的内容(这是一个数组),并且每个元素都应该在自己的行上。我在考虑这样的事情:
'\n'.join(areUnusedParams)但是我不知道如何实现它,当我尝试去做的时候,PyCharm一直在抱怨。
发布于 2016-05-11 13:19:35
当您将areUnusedParams的列表添加到showinfo作为第三个参数时,它将引发一个TypeError,如下所示:
Traceback (most recent call last):
File ".../test.py", line 3, in <module>
tkMessagebox.showinfo("title","message","thing")
TypeError: showinfo() takes from 0 to 2 positional arguments but 3 were given由于您希望'\n'.join(areUnusedParams)是消息的一部分,所以需要将它添加到消息中,而不是作为附加参数传递:
tkMessageBox.showinfo('Error!',
'The following parameters are unchanged throughout the C-files and are also not present in parameter.txt:\n' \
+ '\n'.join(areUnusedParams))我假设所有的areUnusedParams都是字符串,但为了彻底起见,如果它们不是,那么传递给str.join是一件无效的事情,在这种情况下,可以使用map将所有字符串转换为字符串。
'\n'.join(map(str,areUnusedParams))https://stackoverflow.com/questions/37163508
复制相似问题