On 4/2/06, Georg Brandl <[EMAIL PROTECTED]> wrote: > Crutcher Dunnavant wrote: > > Python currently supports 'S % X', where S is a strinng, and X is one of: > > * a sequence > > * a map > > * treated as (X,) > > > > But I have some questions about this for python 3000. > > > > 1. Shouldn't there be a format method, like S.format(), or S.fmt()? > > Possible, but why? "%" works quite fine. "Abusing" the modulus operator > is okay in this context since the symbol gives a nonoverseeable clue to > what the construct is doing.
Why? Because: 1 It is trivially cheap, format() would be the same function as __rmod__ 2 It adds consistency with lower(), strip(), and other methods which produce new strings. 3 I am not arguing _against_ syntactic support, I am arguing _for_ a method; we can keep the syntactic support. > > > 2. What about using __call__ instead of / in addition to __rmod__? > > * "time: %s"(time.ctime()) == "time: %s" % time.ctime() > > * "%(a)s %(b)s"(a=1, b=2) == "%(a)s %(b)s" % {'a'=1, 'b'=2} > > Damn ugly. How would you explain to a newbie that you can _call_ a string? > And that _calling_ a string does a formatting operation? > For me, string formatting with "%" is fine as it is. This is a non-argument. I'd do it the same way that we currently explain that you can _modulo_ or _multiply_ a string. The basic argument goes something like this: While addition and multiplication are binary operations, string formatting usually has more elements involved, and as such, treating it as a binary operation is a bit strange. Especially when keyword formatting is involved. It so happens that python has a well developed syntax for exactly this sort of relationship, and it is the _call_ syntax. So this reduces the complexity of the language for the learner. > > BTW, has anyone seen string.Template being used somewhere? > > Georg > > _______________________________________________ > Python-3000 mailing list > Python-3000@python.org > http://mail.python.org/mailman/listinfo/python-3000 > Unsubscribe: > http://mail.python.org/mailman/options/python-3000/crutcher%40gmail.com > -- Crutcher Dunnavant <[EMAIL PROTECTED]> littlelanguages.com monket.samedi-studios.com _______________________________________________ Python-3000 mailing list Python-3000@python.org http://mail.python.org/mailman/listinfo/python-3000 Unsubscribe: http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com