Hmm, I am pretty sure that you do not need nor really want it, but Python has provision for computing a variable name. Simply it is a rather advanced feature and the normal way is to use mappings (dict
) or sequence (list
or tuple
) containers.
Here, you would use:
all = []
all.append([['mortem' 'cliffi' 'gear' 'lerp' 'control']])
all.append([['video' 'player' 'stori' 'book' 'think' 'narr' 'kill']])
num = 0
print(all[0])
BTW, this syntax is weird, because you are essentially concatenating adjacent litteral string...
But if you really, really need it you can build a interpolator of variables:
def getvar(name):
if name in locals():
return locals()[name]
elif name in globals():
return globals()[name]
else:
raise NameError(repr(name) + ' is not defined')
You can then do:
all0 = [['mortem' 'cliffi' 'gear' 'lerp' 'control']]
all1 = [['video' 'player' 'stori' 'book' 'think' 'narr' 'kill']]
num = 0
print(getvar("all%d" % num))
and get as expected:
[['mortemcliffigearlerpcontrol']]