2016-03-28 17 views
1

我試圖創建一個腳本,將抓住主機名和IP地址,並將它們寫入一個列表,我可以壓縮到一個單獨的字典。除了變量中沒有任何數字的事實,我只想得到'。'。部分而不是數字。真的不知道是什麼之前,我做錯了,因爲這並沒有發生在我身上......看看:問題追加IP地址字符串從for循環到列表

HOST_NAME = [] 
IP_ADDRESS = [] 

ADDITION_NAME = "Please enter a word or two explaining the addition (used for file name): " 

ENTRY_AMOUNT = int(input("How many hosts will need records? ")) 

for number in range(ENTRY_AMOUNT): 
    hostname = raw_input("What is the hostname of the host: ") 
    address = raw_input("What is the IP address of the host: ") 
    HOST_NAME.append(hostname) 
    IP_ADDRESS.append(IP_ADDRESS) 


A_RECORD_ENTRY = dict(zip(HOST_NAME,IP_ADDRESS)) 


print HOST_NAME # test for correct appendages 
print IP_ADDRESS # test for correct appendages 
print A_RECORD_ENTRY # testing code for dictionary output 

這是給我的輸出:

C:\Users\fallacy>a_record_add.py 
How many hosts will need records? 1 
What is the hostname of the host: test 
What is the IP address of the host: 192.168.1.1 
['test'] 
[[...]] 
{'test': [[...]]} 

它只是增加了如前所述,我沒有遇到過這樣的問題,所以請讓我知道我做錯了什麼!非常感激!

回答

2
IP_ADDRESS.append(IP_ADDRESS) 

我想你的意思是寫:

IP_ADDRESS.append(address) 
+0

事實上完全忽視了,謝謝! – Fallacy11

+0

如果這解決了您的問題,請接受@Kevin的回答,以便其他人知道我們不需要寫回答!謝謝! –