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:

  1. globals() list of global variables.
  2. globals()[cp_props[x]] selection list - is, global variable.
  3. globals()[cp_props[x]][1] second element of that global variable.

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -