Center a formatted row of integers in Python?
<p>I am a bit new to Python, having dabbled in VB.NET, C, and a few other odd languages, so I am finding the approaches used before don't always apply to Python.  In this case, I want to print out a series of integer values into columns and center them in as small amount of code as possible.</p>

<p>With plain strings, this is easy as:</p>

<pre><code>print "%s|%s|%s|%s"   \
      % (s1.center(w), s2.center(x), s3.center(y), s4.center(z))
</code></pre>

<p>Where <code>w</code> through <code>z</code> is some integer value specifying the width of the field that the strings, <code>s1</code> through <code>s4</code>, should be center in.</p>

<p><br />Doing the same with numbers when I want to use format specifiers like <code>%0.2x</code> or <code>%4d</code> won't work because integers don't have a <code>center</code> function.</p>

<p>Using a more C-oriented approach, I could convert each integer independently:</p>

<pre><code>s1 = str("%0.4x" % (i)).center(w)
s2 = str("%0.2x" % (i)).center(x)
s3 = str("%0.2x" % (i)).center(y)
s4 = str("%0.8x" % (i)).center(z)
print "%s|%s|%s|%s" % (s1, s2, s3, s4)
</code></pre>

<p><br />But that seems to be "unpythonic", if I am picking up the lingo correctly.  What would be a good "pythonic" way to do this?  It needs to be something that works with Python 2.4 and 2.7 (I am working in both environments).</p>

<p>Thanks!</p>
