title: Variables for width in Python format string
body: <p>In order to print a header for tabular data, I'd like to use only one format string <code>line</code> and one spec for column widths <code>w1, w2, w3</code> (or even <code>w = x, y, z</code> if possible.)  </p>
  
  <p>I've looked at <a href="https://stackoverflow.com/questions/9535954/python-printing-lists-as-tabular-data">this</a> but <code>tabulate</code> etc. don't let me justify things in the column like <code>format</code> does.  </p>
  
  <p>This approach works:  </p>
  
  <pre><code>head = 'eggs', 'bacon', 'spam'  
  w1, w2, w3 = 8, 7, 10  # column widths  
  line = '  {:{ul}&gt;{w1}}  {:{ul}&gt;{w2}}  {:{ul}&gt;{w3}}'  
  under = 3 * '='  
  print line.format(*head, ul='', w1=w1, w2=w2, w3=w3)  
  print line.format(*under, ul='=', w1=w1, w2=w2, w3=w3)  
  </code></pre>
  
  <p>Must I have individual names as widths <code>{w1}</code>, <code>{w2}</code>, ... in the format string? Attempts like <code>{w[1]}</code>, <code>{w[2]}</code>, give either <code>KeyError</code> or <code>keyword can't be an expression</code>.   </p>
  
  <p>Also I think the <code>w1=w1, w2=w2, w3=w3</code> is not very succinct. Is there a better way? </p>