Using print instead of file.write(str)

Bruno Desthuilliers bdesth.quelquechose at free.quelquepart.fr
Fri Jun 2 19:47:45 EDT 2006


Sion Arrowsmith a écrit :
> A.M <alanalan at newsgroup.nospam> wrote:
> 
>>I found print much more flexible that write method.
> 
> 
> "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))

(which BTW should be faster, since it's only one I/O, instead of ten 
with your version.)

Now, given:

   bird = "parrot"
   beautiful = "dead"

How would you do the following with f.write() ?

   print "this", bird, "is", beautiful

(without using string formating, of course...)



More information about the Python-list mailing list