我对这门语言非常陌生,在使用一个名为LatencyList的类时遇到了一些问题
完整的代码可以在这里找到:http://pastebin.com/b5bemMsW
在这个类中,我有两个方法,它们不需要引用对象(self),但是我不能删除"self“参数而不使DocTest失败:
def crop_latencies(self, lat_list):
"""
Return "lat_list" with only latencies (exclude all None(s) that mean PacketLoss)
"""
cropped_list = []
for latency in lat_list:
if latency is not None:
cropped_list.append(latency)
return cropped_list
def count_packetlost(self, lat_list):
"""
Return None(packetloss) counts in "lat_list"
"""
counter = 0
for latency in lat_list:
if latency is None:
counter += 1
return counter在这里,如果我尝试删除“DocTest”参数,则在自我期间会出现错误:http://pastebin.com/mm8YgRSM
我做错了什么?
编辑:解决方案在像moep建议的方法之前添加@staticmethod
谢谢!
发布于 2014-08-21 22:53:54
试着在你的函数声明前面使用@staticmethod。
class A:
def a_method(self):
pass
@staticmethod
def a_static_method():
pass请访问LINK了解更多信息。
https://stackoverflow.com/questions/25429335
复制相似问题