[Python-ideas] py3k: adding "print" methods to file-like objects

Tal Einat taleinat at gmail.com
Thu Mar 13 23:40:03 CET 2008


I prefer using partial than introducing new syntax:

print_to_stderr = functools.partial(print, file=sys.stderr)

print_to_stderr('first line')
print_to_stderr('second line')
...

- Tal

On Thu, Mar 13, 2008 at 10:56 PM, Erick Tryzelaar <
idadesub at users.sourceforge.net> wrote:

> This might be a minor thing, but I kind of wish that I could write this:
>
> sys.stderr.print('first line')
> sys.stderr.print('another line here')
> sys.stderr.print('and again')
>
> instead of:
>
> print('first line', file=sys.stderr)
> print('another line here', file=sys.stderr)
> print('and again', file=sys.stderr)
>
> As it's a lot easier to read for me. Of course you can always add
> spaces to make the lines line up, but with a long print statement your
> eye has to go a long distance to figure out what file, if any, you're
> printing to. It could be pretty simple to add:
>
> class ...:
>  def print(*args, **kwargs):
>    io.print(file=self, *args, **kwargs)
>
> I haven't been able to find any discussion on this, has this already
> been rejected?
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20080314/eb651a88/attachment.html>


More information about the Python-ideas mailing list