[Python-3000] print() parameters in py3k

Barry Warsaw barry at python.org
Tue Nov 21 14:28:32 CET 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Nov 20, 2006, at 8:38 PM, Guido van Rossum wrote:

> I'm still confused. Are you proposing that in order to print to a
> different file we do
>
> save_file = print.file
> try:
>  print.file = open("log.txt", "a")
>  print(x, y, z)
> finally:
>  print.file = save_file

You could do that, but to make it more convenient I was thinking  
about adding class methods, such as the clone() I used earlier.   
Let's rename that method though so that it's hopefully clearer:

lprint = print.open('log.txt', 'a')
lprint(x, y, z)
lprint.close()

- -or-

lprint.file.close()

lprint is just another instance of whatever class 'print' is, except  
that its 'file' attribute is set to the opened log.txt file.

Regardless of whether you like this or not <wink>, does that make sense?

- -Barry



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)

iQCVAwUBRWL/AHEjvBPtnXfVAQJ1TQQAltC6uJEpzkYXyb4Zr6hRrWsPmYfOyJnp
EOLieDvn/pTOVgA+iAuccEtac+Yp5Kl8bR+5s4B8XSLoD8gbKt7aMwmwBdy7fIOc
2OvH+pb2rn8laMAzp/OTzg7OF+ptJFXKdfOx8+pZdy41htV+6U8rsHWUCo2F59Sj
q3XzVDbMF44=
=DycV
-----END PGP SIGNATURE-----


More information about the Python-3000 mailing list