将for循环中的IP地址字符串追加到lis时出现问题

2024-04-20 08:52:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试创建一个脚本,它将获取主机名和IP地址,并将它们写入一个可以压缩到单独字典中的列表中。除了变量中没有任何数字之外,我只得到“.”部分,而不是数字。我不太确定我做错了什么,因为我以前从未发生过这种事……看看:

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

这是给我的输出:

^{pr2}$

它只是添加了点,因为我没有遇到过这种情况,所以请让我知道我做得不对!非常感谢!在


Tags: thenameiphostforinputrawis