Search code examples
pythoncompiler-errorssyntax-errorabaqus

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


I get the error

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

and the error is caused by my code

name=inst1name+'-'+setName 

I know the problem is: inst1name is a set object, however this error never come up before when I run the script.

Do you know why is this? and how can I solve it?


Solution

  • You could explicitly convert the set to its string representation like this:

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

    But a better way would be to use string composition like this:

    name = '%s-%s' % (inst1name, setName)
    

    Or even string.format like this:

    name = '{}-{}'.format(inst1name, setName)