[英]How would I improve this simple python class and its docstring ?
这是一个简单的过滤器,我一直在通过串行连接读取数据的项目中使用它,并且认为将它用作我第一次尝试编写文档字符串会很好。 有没有人有什么建议? 我一直在阅读 PEP 257。因为它是 class,关键字 arguments 应该跟在__init__
之后吗?
如果有更好的方法来编写它的任何部分(不仅仅是文档字符串),如果人们能指出我正确的方向,我将不胜感激。
class Filter(object) :
"""Return x if x is greater than min and less than max - else return None.
Keyword arguments:
min -- the minimum (default 0)
max -- the maximum (default 0)
Notes:
Accepts integers and integer strings
"""
def __init__(self, min=0, max=0) :
self.min = min
self.max = max
def __call__(self, input) :
try :
if int(input) <= self.max and int(input) >= self.min :
return int(input)
except : pass
使用 pylint 和 pep8 检查代码约定和常见的输入错误通常是个好主意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.