print(f) for files .. and is print % going away?

Esmail ebonak at hotmail.com
Thu Apr 30 22:42:03 EDT 2009


hello,

Lie Ryan wrote:
> 
> There has never been print-with-formatting in python, what we have is 
> the % string substitution operator, which is a string operation instead 
> of print operation.

Yes, I see that now, thanks for clarifying it. I guess I thought
so because I've always associated the % formatting with printing.

>> I am wondering if there is a way to use print to write
>> formatted output to files?
> 
> Of course:
> 
> f = open(...)
> open.write('%s' % foo)

very nice ..

> or using the new superpowerful str.format()
>  >>> 'foo: {0} bar: {baz:3.1f} {1:e}'.format(123, 456.789, baz = 123.456)
> 'foo: 123 bar: 123.5 4.567890e+02'

I'll have to check it out - thanks again,

Esmail




More information about the Python-list mailing list