title: Roughly approximate the width of a string of text in Python?
body: <p>How would one, using Python, approximate the font width of a given string of text? </p>
  
  <p>I am looking for a function with a prototype similar to:</p>
  
  <pre><code>def getApproximateFontWidth(the_string, font_name="Arial", font_size=12):
     return ... picas or pixels or something similar ...
  </code></pre>
  
  <p>I'm not looking for anything very rigorous, an approximation will be fine. </p>
  
  <p>The motivation for this is that I am generating a truncated string in my webapp's backend and sending it to the front-end to be displayed. Most of the time the strings are lower case, but sometimes the strings are in all caps, making them very wide. If the string isn't properly trucated it looks ugly. I'd like to know how much to truncate the strings based on their approximate width. If it's off by 10% it's not a big deal, this is a cosmetic feature.</p>