Using print instead of file.write(str)

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Sun Jun 4 22:49:45 EDT 2006


Tim Roberts a écrit :
> Bruno Desthuilliers <bdesth.quelquechose at free.quelquepart.fr> wrote:
> 
> 
>>Sion Arrowsmith a écrit :
>>
(snip)
>>>"more flexible"? More convenient, yes. More powerful, maybe. But I
>>>don't see more flexible. Everything print can to stdout.write() can
>>>do. The reverse isn't true. eg (this appears to be a FAQ on this
>>>group, although I can't find it in the FAQ):
>>>
>>>for x in range(10):
>>>    sys.stdout.write(str(x))
>>>
>>>to print:
>>>
>>>0123456789
>>
>>The reverse isn't true ???
>>
>>  print "".join(str(x) for x in range(10))
>  
> What he meant it that it is impossible to produce "0123456789" using 10
> separate print statements, while it IS possible with 10 separate writes.

why on earth would someone try to use 10 consecutive I/O operations on 
the same stream when it can be done with 1 ???



More information about the Python-list mailing list