On 6 Dec 2006 18:33:26 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote: > "Calvin Spealman" <[EMAIL PROTECTED]> wrote: > > > I am not aware of anything in the stdlib to do this easily, but its > > pretty easy to get them. See this example: > > > > class format_collector(object): > > def __init__(self): > > self.names = [] > > def __getitem__(self, name): > > self.names.append(name) > > return '' > > > > collector = format_collector() > > "%(foo)s %(bar)s" % collector > > assert collector.names == ['foo', 'bar'] > > > > Of course, wrapping this functionality into a simple function is > > straightforward and will look better. > > You should return a value like 0 instead of ''. > > >>> collector = format_collector() > >>> "%(foo)s %(bar)d" % collector > > Traceback (most recent call last): > File "<pyshell#3>", line 1, in <module> > "%(foo)s %(bar)d" % collector > TypeError: int argument required > > -- > http://mail.python.org/mailman/listinfo/python-list >
Good thinking with returning 0 and using a set. Maybe something added to the stdlib would be welcome instead of anyone needing it writing this little class? -- Read my blog! I depend on your acceptance of my opinion! I am interesting! http://ironfroggy-code.blogspot.com/ -- http://mail.python.org/mailman/listinfo/python-list