[Python-Dev] Replacement for print in Python 3.0
Gareth McCaughan
gmccaughan at synaptics-uk.com
Tue Sep 6 17:53:49 CEST 2005
> > On 9/6/05, Barry Warsaw <barry at python.org> wrote:
> > > printf('$1 forgot to frobnicate the $2!\n', username, file.name,
> > > to=sys.stderr)
...
> For me, the problem with that proposal is not the precise format syntax,
> but the fact that formatting is tied to a specific function which _also_
> outputs stuff to screen.
So borrow a trick from Common Lisp and use a destination of None
to mean "return the formatted text as a string".
>>> x = printf("$2 $1", 123,321)
321 123
>>> print x
None
>>> x = printf("$2 $1", 123,321, to=None)
>>> print x
321 123
Or is that too cryptic?
--
g
More information about the Python-Dev
mailing list