Filter for reading data over a serial connection 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) &lt;= self.max and int(input) &gt;= self.min : 
                return int(input)
        except : pass
class Filter(object) :
    """Return x if x is greater than min and less than max - else return None. 


How about "if x is between min and mix"?

    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) :


min and max are builtin python functions. I suggest not using the same names if you can help it.

        self.min = min
        self.max = max
    def __call__(self, input) :
        try :
            if int(input) &lt;= self.max and int(input) &gt;= self.min : 


In python you can do: if self.min &lt; int(input) &lt;= self.max

                return int(input)

        except : pass


Don't ever do this. DON'T EVER DO THIS! ARE YOU LISTENING TO ME? DON'T EVER DO THIS.

You catch and ignore any possible exception. But in python everything raises exceptions, and you'll not be notified if something goes wrong. Instead, catch only the specific exceptions you are interested in, in this, case ValueError.

Futhermore, having a filter that tries to accept string or integers like this just a bad idea. Convert your input to integers before you use this function, not afterwards.

The interface you provide doesn't seem all that helpful. The calling code is going to have to deal with None which will be a pain. Usually in python we'd do something operating on a list or as a generator.

Perhaps you want something like this:

return [int(text) for text in input if min &lt; int(text) &lt; max]