我已经在构造函数中初始化了我的队列,如下所示:
class PingSweeper():
def __init__(self,Networks,pending):
self.Networks = ['192.168.1.0/28']
self.pending = queues.Queue()
当我创建PingSweeper对象时,它希望将Networks和Pending作为参数传入。以下是我创建PingSweeper对象的方法:
ping = PingSweeper('0.0.0.0',pending)
第一个变量是Networks,它是一个数组,所以我传递'0.0.0.0',pending是一个队列,我不知道要传递什么等待挂起,它告诉我挂起未定义。任何帮助将不胜感激。
答案 0 :(得分:0)
三个问题
Networks
应该是一个数组,您将其作为字符串传递ping = PingSweeper('0.0.0.0',pending)
收到“待定未定”,则表示您尚未在该范围内为pending
定义变量以下是适当结构的一个小例子。 python变量也应该是小写的,比如networks
import queue
class PingSweeper():
def __init__(self, networks, pending):
self.networks = networks
self.pending = pending
scan_networks = ['192.168.1.0/28']
ping = PingSweeper(scan_networks, queue.Queue())
for net in ping.networks:
print("Ping:", net)
ping.pending.put('0.0.0.0')
ping.pending.put('127.0.0.0')
while not ping.pending.empty():
print("Scanning:", ping.pending.get())
答案 1 :(得分:0)
您可能希望为网络和待处理参数设置默认值:
import Queue
class PingSweeper():
def __init__(self, Networks=['192.168.1.0/28'], pending=Queue.Queue()):
self.Networks = Networks
self.pending = pending
print self.Networks
print self.pending
ping = PingSweeper('0.0.0.0')
ping.pending.put('192.168.1.1')
ping.pending.put('192.168.1.2')
print ping.pending.get()