简体   繁体   中英

Assign variable name based on variable string in for loop

dblist = ('database1', 'database2', 'database3', 'database4', 'database5', 'database6', 'database7') 
for db in dblist:
    cursor = conn.cursor()
    cursor.execute("select SYSTEM from automation/awdclient where db = " + "'" + db + "'" + "")
    for row in cursor:
        activesystem.db = row[0]
    cursor.close
    conn.close
print activesystem.database1
print activesystem.database2

What I am doing is retrieving a system name from a db. I want to assign a variable equal to that system name, with the variable name system.whatever the db string was.

采用:

activesystem.setattr(db, row[0])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM