[Python-3000] print() parameters in py3k

Ron Adam rrr at ronadam.com
Tue Nov 21 16:31:24 CET 2006


Barry Warsaw wrote:
> -----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?


I'll add 2 cents here...  (or possibly less)

I agree with others here the print function probably should be as simple and 
easy to use as possible, basically nearly identical to the current print use, 
but as a function.  It's easy and generalized enough to work in most situations 
and it fits the use case of an easy convenient built-in way to output basic text.

I think maybe there could be more specialized print methods on possibly a 
console (and printer?) object in the library.  That would then match the file 
objects use of write and writeline.

So you then might have a console.print() and console.printline(), and 
printer.print() and printer.printline(),  along with the built in file.write() 
and file.writeline().  But I think having a generic print object somehow doesn't 
fit this pattern well.

And weather or not these types of objects ever get added to the library, I can't 
see how it would effect the print function use in any way.

Does this make more (or less) sense?

Cheers,
    Ron








More information about the Python-3000 mailing list