I have the following code:
var_one = var_two[var_three-1]
var_one = "string_one" + var_1
And I need to do the following to it:
var_four = 'string_two', var_one
However, this returns the following error:
TypeError: Can't convert 'tuple' object to str implicity
I have tried things such as str(var_one) and using strip but these did not work.
What can I do to achieve the result I require?
EDIT – Here are what the variables contain:
var_one: new variable
var_two: tuple
var_three: integer
var_four: new
EDIT2:
The line in the program that makes the error is: os.system(var_four)
Your code looks fine as is.
Try running
import pdb; pdb.set_trace()in your program to see if you can find the line triggering the error.EDIT: You’ll want to use
''.join(var_four)to convertvar_fourinto a string before adding it to whatever it is you want to use it. Please note that this will actually create a new string and not overwritevar_four. See Python 3 string.join() equivalent?Also, you should be using the
subprocessmodule instead ofos.system. See the Python 3.x documentation.