This is a simple filter that I have been using for a project reading data over a serial connection, and thought it would be good to use it as my first attempt to write docstrings. Does anyone have any suggestions? I have been reading PEP 257. As it is a class, should the keyword arguments come after the __init__
?
If there is a better way to write any part of it (not only the docstrings), I would appreciate it if people could point me in the right direction.
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
It's usually a good idea to use pylint and pep8 to check the code conventions and common typing mistakes.