Re: method to intercept string formatting % operations

2010-02-05 Thread Steven D'Aprano
On Fri, 05 Feb 2010 16:49:00 +0100, Jean-Michel Pichavant wrote: > Anyway why would you want to use the tuple form ? it's beaten in every > aspect by the dictionary form. Except convenience, efficiency and readability. "%s %s" % (1, 2) versus "%(a)s %(b)s" % {'a': 1, 'b': 2} I'm all in favou

Re: method to intercept string formatting % operations

2010-02-05 Thread Raymond Hettinger
On Feb 5, 6:57 am, bradallen wrote: > Hello, > > For container class derived from namedtuple, but which also behaves > like a dictionary by implementing __getitem__ for non-integer index > values, is there a special reserved method which allows intercepting % > string formatting operations? I woul

Re: method to intercept string formatting % operations

2010-02-05 Thread Brad Allen
On Fri, Feb 5, 2010 at 9:49 AM, Jean-Michel Pichavant wrote: > Anyway why would you want to use the tuple form ? it's beaten in every > aspect by the dictionary form. I'm subclassing a namedtuple, and adding some additional functionality such as __getitem__, __setitem__, so that the namedtuple a

Re: method to intercept string formatting % operations

2010-02-05 Thread Jean-Michel Pichavant
bradallen wrote: Hello, For container class derived from namedtuple, but which also behaves like a dictionary by implementing __getitem__ for non-integer index values, is there a special reserved method which allows intercepting % string formatting operations? I would like for my container type

method to intercept string formatting % operations

2010-02-05 Thread bradallen
Hello, For container class derived from namedtuple, but which also behaves like a dictionary by implementing __getitem__ for non-integer index values, is there a special reserved method which allows intercepting % string formatting operations? I would like for my container type to behave appropria