On Thu, Apr 12, 2012 at 7:35 PM, Cameron Simpson <[email protected]> wrote:
> I've found myself using a Python gotcha as a feature.
>
> I've got a budding mail filter program which keeps rule state in a
> little class instance. Slightly paraphrased:
>
> class RuleState(object):
> def __init__(self, M, maildb_path, maildirs={}):
> [...]
> self.maildirs = maildirs
>
> Would experienced users please mock me?
Well, no mocking; the same technique on a non-method function is a
pretty normal way of maintaining state. But wouldn't it be simpler to
use a class variable?
class RuleState(object):
maildirs = {}
def __init__(self, M, maildb_path):
Then just use self.maildirs everywhere, never assign to it.
ChrisA
--
http://mail.python.org/mailman/listinfo/python-list