. Python 2.1 function attributes

Toby Dickenson mbel44 at dial.pipex.net
Mon Feb 5 09:15:48 EST 2001


"Alex Martelli" <aleaxit at yahoo.com> wrote:

>> I don't think print>> is ever a good substitute for .write(), except in
>
>So far, we agree, up to the "except" excluded:-).
>
>> those cases where .write() is being used for human-readable output and the
>> author didn't want to do the stdout redirection dance around plain
>"print".
>
>The redirection minuet is one thing, but I claim that write
>with a %-format doesn't leave me wanting for decent ways to
>do output.  A printlike function would be better, but I
>don't hunger for it often, because write-plus-% does it well;

Not well enough, apparently, judging by the number of packages that
grew out of the need for exactly this type of output. A need that
wasnt satisfied by file.write("formatting"%(data))

The two that I am familiar with are the templating parts of quixote
http://www.mems-exchange.org/software/python/quixote/
and DC's DTML. DTML is part of Zope - It currently currently does alot
more than just formatting, but I understand that was its original (and
only) goal.

The real problem (IMO) with file.write("formatting"%(data)) is that
the expressions that build up the data are out of line with the static
content. Its harder for the programmer to visualize the bigger picture
of his output, because he has to mentally interleave the dynamic and
static parts. The problem is greater in functions whose only job is
output formatting.

The disadvantage is comparable to the difference between using an
infix notation, or function notation for arithmetic.


ps. Ive used both dtml and quixote templates, but largely abandonned
them both in favor of print >>



Toby Dickenson
tdickenson at geminidataloggers.com



More information about the Python-list mailing list