[Python-ideas] Printf function?
Masklinn
masklinn at masklinn.net
Sun May 13 12:00:49 CEST 2012
On 2012-05-13, at 09:22 , Steven D'Aprano wrote:
> Define "easier to use". Calling a method and passing its output to print seems to be pretty easy to me.
>
> The major issue with printf is that it prints AND formats. That means you can't easily capture its output. A simpler approach is to have one function that handles the printing, and another function (or possibly a choice of multiple functions) that handles the formatting, then simply pass the output of the second to the first.
An other option is to have a formatting function similar to Common
Lisp's format[0]: it formats a string and
* If provided with a stream (or stream-like) argument writes the
formatted string to the stream and returns `nil`
* Otherwise returns the formatted string
The function formats and prints, but capturing the output (to a
non-standard stream or to a string) is trivial.
[0] http://www.lispworks.com/documentation/HyperSpec/Body/f_format.htm#format
More information about the Python-ideas
mailing list