我想使用用戶輸入引用字典,以便用戶將選擇使用哪個字典。如何根據用戶的選擇選擇字典?
例如,給定的字典
cisco = {'uname': 'user_name', 'password': 'pass', 'backup_make': 'Write memory', 'backup_location_device': 'nvram:/startup-config'};
bnt = {'uname': 'user_name', 'password': 'pass', 'backup_make': 'save', 'backup_location_device': 'getcfg'};
ods = {'uname': 'user_name', 'password': 'pass', 'backup_make': 'None', 'backup_location_device': '/config/juniper.conf.gz'};
f5 = {'uname': 'user_name', 'password': 'pass', 'backup_make': 'tmsh save /sys ucs my.config.ucs', 'backup_location_device': '/var/local/ucs/my.config.ucs'};
hp = {'uname': 'user_name', 'password': 'pass', 'backup_make': 'save', 'backup_location_device': '/config.cfg'};
juniper = {'uname': 'user_name', 'password': 'pass', 'backup_make': 'None', 'backup_location_device': '/config/juniper.conf.gz'};
alteon = {'uname': 'user_name', 'password': 'pass', 'backup_make': 'save', 'backup_location_device': 'getcfg'};
我要像做
vendor = raw_input("Enter the vendor's name: ")
print ("the username: " + vendor["uname"] +
"; the password is: " + vendor["password"])
我想用 「思科」, 「BNT」, 「消耗臭氧層物質」 等作爲指標而不使用if
聲明。
謝謝!
更正您的數據結構,使用一個字典來嵌套所有7個字典 –