[Python-ideas] py3k: adding "print" methods to file-like objects
Greg Ewing
greg.ewing at canterbury.ac.nz
Sat Mar 15 01:27:32 CET 2008
> On Thu, Mar 13, 2008 at 3:56 PM, Erick Tryzelaar
> <idadesub at users.sourceforge.net> wrote:
>
>> instead of:
>>
>> print('first line', file=sys.stderr)
>> print('another line here', file=sys.stderr)
>> print('and again', file=sys.stderr)
Perhaps it would help if there were a function
fprint(f, *args):
print(file = f, *args)
then the above could be written
fprint(sys.stderr, 'first line')
fprint(sys.stderr, 'another line here')
fprint(sys.stderr, 'and again')
which to me is a lot easier to read, since the file argument
is in a consistent place, making it easier to see that it's
the same from one line to the next.
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.
--
Greg
More information about the Python-ideas
mailing list