[Python-ideas] py3k: adding "print" methods to file-like objects
Erick Tryzelaar
idadesub at users.sourceforge.net
Sat Mar 15 02:39:43 CET 2008
On Fri, Mar 14, 2008 at 5:27 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Also, it enables making the file argument very abbreviated, e.g.
>
> f = sys.stdout
> fprint(f, 'first line')
> fprint(f, 'another line here')
> fprint(f, 'and again')
>
> Otherwise, the shortest you can get it down to is 'file=f',
> which is 6 times as long. It might not seem much, but that's
> 5 less characters of print arguments that you can fit in
> without having to split the line.
In that case I think partials a better option, when you could do:
p = partial(print, file=sys.stderr)
p('first line')
p('another line here')
p('and again')
I completely forgot about partial which does a good job of filling in
for what I wanted. I just need to consider the combination of the py3k
stuff a bit more.
More information about the Python-ideas
mailing list