String concatenation vs. string formatting

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Jul 10 09:42:48 EDT 2011


Andrew Berg wrote:

> How should I go about switching from concatenation to string formatting
> for this?
> 
> avs.write(demux_filter + field_filter + fpsin_filter + i2pfilter +
> dn_filter + fpsout_filter + trim_filter + info_filter)
> 
> I can think of a few ways, but none of them are pretty.

fields = (demux_filter, field_filter, fpsin_filter, i2pfilter, 
          dn_filter, fpsout_filter, trim_filter, info_filter)
avs.write("%s"*len(fields) % fields)

works for me.




-- 
Steven




More information about the Python-list mailing list