title: sprintf like functionality in Python
body: <p>I would like to create a string buffer to do lots of processing, format and finally write the buffer in a text file using a C-style <code>sprintf</code> functionality in Python. Because of conditional statements, I can’t write them directly to the file.</p>
  
  <p>e.g pseudo code:</p>
  
  <pre><code>sprintf(buf,"A = %d\n , B= %s\n",A,B)
  /* some processing */
  sprint(buf,"C=%d\n",c)
  ....
  ...
  fprintf(file,buf)
  </code></pre>
  
  <p>So in the output file we have this kind of o/p:</p>
  
  <pre><code>A= foo B= bar
  C= ded
  etc...
  </code></pre>
  
  <p><strong>Edit, to clarify my question:</strong><br>
  <code>buf</code> is a big buffer contains all these strings which have formatted using sprintf.
  Going by your examples, <code>buf</code> will only contain current values, not older ones.
  e.g first in <code>buf</code> I wrote <code>A= something ,B= something</code> later <code>C= something</code> was appended in the same <code>buf</code>, but in your Python answers <code>buf</code> contains only last value, which is not I want - I want <code>buf</code> to have all the <code>printf</code>s I have done since the beginning, like in <code>C</code>.</p>