On Sat, 23 Jul 2005 20:07:25 -0600, Steven Bethard <[EMAIL PROTECTED]> wrote:
>[Raymond Hettinger] >>>class Cache(dict): >>> def __init__(self, n, *args, **kwds): >>> self.n = n >>> self.queue = collections.deque() >>> dict.__init__(self, *args, **kwds) > >[Bengt Richter] >> Minor comment: There is a potential name collision problem for keyword >> n=something, >> so what is considered best practice to avoid that? __n or such as the n arg? > >I don't know what best practice is, but if you want to guarantee to >avoid the name collision, you can write: > >def __init__(*args, **kwargs): > self = args[0] > self.n = args[1] > self.queue = collections.deque() > dict.__init__(self, *args[2:], **kwargs) > >It's not pretty though. ;) Bullet proofing doesn't have to be ;-) Best solution I've seen yet, thanks. Regards, Bengt Richter -- http://mail.python.org/mailman/listinfo/python-list