python - abaqus脚本: TypeError: cannot concatenate 'str' and 'Set' objects

标签 python compiler-errors syntax-error abaqus

我得到错误

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

错误是我的代码引起的
name=inst1name+'-'+setName 

我知道问题是:inst1name是一个设置对象,但是在运行脚本之前,永远不会出现此错误。

你知道为什么吗以及我该如何解决?

最佳答案

您可以像这样将set显式转换为其字符串表示形式:

name = inst1name + '-' + str(setName)

但是更好的方法是使用像这样的字符串组合:
name = '%s-%s' % (inst1name, setName)

甚至像这样的string.format:
name = '{}-{}'.format(inst1name, setName)

关于python - abaqus脚本: TypeError: cannot concatenate 'str' and 'Set' objects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25425265/

相关文章:

python - 为数据库中现有条目生成 slug 字段数据

python - 在 Tkinter 中运行窗口最小化命令

xcode - 在Xcode上取消引用void *警告

python-3.x - 使用x范围内的语法错误

syntax-error - OpenBUGS中的:“Multiple definitions of node”错误。

Python 2.6 版本语法错误

python - Tkinter 窗口关闭后有什么办法可以做一些事情吗?

python - 如何使用汤从页面中提取列中的数据

Java - 圆柱程序 - 无法使用 main

c++ - 使用G++编译C++程序时出错