我正在尝试使用OOP python,我不确定__repr__函数继承.由于父类函数看起来像这样:
def __repr__(self):
'''Returns representation of the object'''
return("{}({!r})".format("Class name", self._param))
Run Code Online (Sandbox Code Playgroud)
我想知道是否更好地使用通用方法(也适用于子类),如下所示:
def __repr__(self):
'''Returns representation of the object'''
return("{}({!r})".format(self.__class__.__name__, self._param))
Run Code Online (Sandbox Code Playgroud)
或者如果在每个班级中覆盖该功能是一个好习惯.
另外,请忽略编码部分,因为我将它留在后面.
我找不到仅使用scapy(而不是 Python 的 stdlib)查找本地 IP 地址的方法。我发现的唯一解决方法是发送一个虚拟包并使用它从源字段中检索地址,但我认为这不是一个好的解决方案。