On Thu, Oct 1, 2009 at 11:03 AM, Brett Cannon <br...@python.org> wrote:
> So I created this last night:
>
> import collections
>
> class braces_fmt(str):
>
>    def __mod__(self, stuff):
>        if isinstance(stuff, tuple):
>            return self.__class__(self.format(*stuff))
>        elif isinstance(stuff, collections.Mapping):
>            return self.__class__(self.format(**stuff))
>        else:
>            return self.__class__(self.format(stuff))
>
> The biggest issue is that ``"%s" % {'a': 42}`` substitutes the dict
> instead of throwing an error that str.format() would do with the code
> above. But what's nice about this is I think I can use this now w/ any
> library that expects % interpolation and it should basically work.

I see how this could allow a user to supply a {}-format string to an
API that accepts only %-format strings. But I still don't see the
transition strategy for the API itself. That is, how does the %-format
API use this to eventually switch to {}-format strings? Could someone
please lay it out for me, step by step, showing what happens in each
version?

Steve
-- 
Where did you get that preposterous hypothesis?
Did Steve tell you that?
        --- The Hiphopopotamus
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to