python打印每个单词,为什么?

2024-09-24 00:35:14 发布

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

我正在为DNS传输制作一个脚本,但是当我输入信息时,它会给我以下错误。
其次,当我删除r={} 我有以下错误。请帮帮我,因为我正在学习,所以我学习很慢

host: couldn't get address for 'm': not found                                                                                            
e                                                                                                                                        
host: couldn't get address for 'e': not found                                                                                            
g
host: couldn't get address for 'g': not found
a
host: couldn't get address for 'a': not found
c
host: couldn't get address for 'c': not found
o
host: couldn't get address for 'o': not found
r
host: couldn't get address for 'r': not found
p
host: couldn't get address for 'p': not found
o
host: couldn't get address for 'o': not found
#!/usr/bin/python

import subprocess

domain = raw_input("Enter you're domain: ")

host = subprocess.Popen(['host','-t','ns',domain],  stdout=subprocess.PIPE).communicate()[0]


result=host
r={}
for i in r:
    print i

    zt = subprocess.Popen(['host','-l',domain,i],   stdout=subprocess.PIPE).communicate()[0]

print zt
  ============================
 Enter you're domain: google.com
 Traceback (most recent call last):
 File "./dns-zone.py", line 17, in <module>
  print zt
 NameError: name 'zt' is not defined

Tags: reyouhostforgetaddressdomain错误
1条回答
网友
1楼 · 发布于 2024-09-24 00:35:14
import subprocess

domain = raw_input("Enter you're domain: ")
host = subprocess.Popen(['host','-t','ns',domain],  stdout=subprocess.PIPE).communicate()[0]
result=host
r={}
for i in r.keys():
    #print i #This is the culprit right here
    zt = subprocess.Popen(['host','-l',domain,i],   stdout=subprocess.PIPE).communicate()[0]

print zt

for循环中有一个print语句,所以每次它循环时,它都在打印i是什么。此外,请确保print zt在循环外部被正确地标记

而且,它看起来i只是一个字母,而不是您可能需要的字符串。这个代码有比你展示的更多的东西吗?r = {}到底充满了什么?您是否需要执行for i in r.keys()以正确地迭代

相关问题 更多 >