我使用Python,即時通訊製作一個函數,讀取一個字符串,根據每行的第一個字執行不同的功能,我做了類似的東西,但它沒有做任何事情:閱讀一個文本並執行不同的功能,python
conf_list='''
host/yes/7200
network/yes/6000
applications/no/6500
'''
list_conf={}
k=0
for line in conf_list.splitlines():
list_conf[k]=line
#print(list_conf[k])
if list_conf[0] == 'host':
print(list_conf[1], list_conf[2]) #output i wanted: yes 7200
elif list_conf[0] == 'network':
print(list_conf[1], list_conf[2]) #output: yes 6000
elif list_conf[0] == 'applications':
print(list_conf[1], list_conf[2]) #output: no 6500
也許這些if和elif不好?
爲什麼是「應用程序」的輸出是「是6500」嗎?它在'conf_list'中是'no 6500'。 – roippi
你是對的,我的錯誤,我現在改變它 –