python - anyone know why this doesn't work? --> [cp_props[x]][1] -
this piece of code doesn't work, , "indexerror: list index out of range" error, not sure why, know why doesn't work? thanks.
print([cp_props[x]][1])
it should name of item in list, name of anothert list , open 2nd element in list???
okay, works this:
globals()[cp_props[x]][1]
but there other more simple way of doing it? thank you.
[cp_props[x]]
one-element list. 1 , element cp_props[x]
, whatever is. element number 0. there no element number 1, that's why selection expression [1]
fails.
expression globals()[cp_props[x]][1]
has totally different meaning. reading left right:
globals()
list of global variables.globals()[cp_props[x]]
selection list - is, global variable.globals()[cp_props[x]][1]
second element of that global variable.
Comments
Post a Comment