title: Python - Create a text border with dynamic size
body: <p>I'm creating a command line script and I'd like there to be box...</p>
  
  <pre><code>+--------+
  |        |
  |        |
  |        |
  +--------+
  </code></pre>
  
  <p>... that will always fit its contents.  I know how to do the top and bottom, but it's getting the ljust and rjust working correctly.  There may be one string substitute per line, or 5, and the len of those strings could be anything between 0 and 80.</p>
  
  <p>I have been doing things like:</p>
  
  <p><code>
  print "|%s|" % (my_string.ljust(80-len(my_string)))
  </code></p>
  
  <p>But holy dang is that messy... And that's just one hardcoded substitution. I have no idea how to make it dynamic with say 2 subs on line one, and 3 subs on line two and 1 sub on line three (all this in a column format).</p>
  
  <p>So for a basic example, I need:</p>
  
  <pre><code>+--------+
  | 1      |
  | 1 2 3  |
  | 1 2    |
  +--------+
  </code></pre>