开发者

Python - why is it not reading my variables?

I'm a py开发者_StackOverflow社区thon newbie and I don't understand why it won't read my IP and ADDR variables in the function dns.zone.query(IP, ADDR)???

import dns.query
import dns.zone
import sys

IP = sys.stdin.readline()
ADDR = sys.stdin.readline()


z = dns.zone.from_xfr(dns.query.xfr(IP , ADDR))
names = z.nodes.keys()
names.sort()
for n in names:
    print z[n].to_text(n)

It works when I pass an actual IP and Domain, but not with the variables... I don't get what's wrong?


readline() will include a trailing newline. You can use sys.stdin.readline().strip()


I would try with:

IP = sys.stdin.readline().strip()
ADDR = sys.stdin.readline().strip()

Add some prints after the variables to debug it:

print '_%s_' % IP
print '_%s_' % ADDR


Try sys.stdin.readline().strip(). You need to remove the newlines.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜