Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulating the name of lists and using them - Python

Status
Not open for further replies.

nvhuser

Programmer
Apr 10, 2015
48
DE
Hello everyone,

I would like to use a list while I am changing its name.
I have the following lists defined label_SUB1, label_SUB2, label_SUB3 and label_SUB4.

Python:
for j in range(1,4):
     for i in range(0,205):
            print "AAA," + str(i+12000027+10000*j) + "," + label_SUB[j][i] + ",33,"
            print ",BBB," + label_SUB[j][i] + ","
            print ",CCC," + str(i+11800027+10000*j)

Thank you for your help!


 
Hi

Assuming label_SUB1 & co. are global variables, something like this :
Code:
[b]print[/b] [i]"AAA,"[/i] + str(i+12000027+10000*j) + [i]","[/i] + globals()[[i]"label_SUB"[/i] + `j`][ignore][i][/ignore] + [i]",33,"[/i]
Not a great coding habit though.


Feherke.
feherke.ga
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top