I have this:
listVar=[]
listSel={'one':'x','two':'code'}
for row in listSel:
exec("%s = '%s'" % (row,listSel[row]))
listVar.append("%s" %row)
print(one,two)
print(listVar)
I convert the row in a variable with exec()
, but i don't know how could i append the new variables in the listVar
; next to this i'm looking for inside the variable in a list with listVar.append("%s" %row)
, my expected answer with print would be:
['x','code']
(Because I'm printing the variables one
and two
)
But when I print listVar
Python answered me:
['one','two']
I don't want to use something like:
listVar.append(one)
Because I'll make a function and I'll not know the rows.
Edit: I need listVar
to be [one,two]
not ['one','two']
.