title: python string format suppress/silent keyerror/indexerror
body: <p>Is there a way to use python string.format such that no exception is thrown when an index is missing, instead an empty string is inserted.</p>
  
  <pre><code>result = "i am an {error} example string {error2}".format(hello=2,error2="success")
  </code></pre>
  
  <p>here,result should be :</p>
  
  <pre><code>"i am an   example string success"
  </code></pre>
  
  <p>Right now, python throws a keyerror and stops formatting. Is it possible to change this behavior ?</p>
  
  <p>Thanks</p>
  
  <p>Edit: </p>
  
  <p>There exists Template.safe_substitute (even that leaves the pattern intact instead of inserting an empty string) , but couldn't something similar for string.format</p>
  
  <p>The desired behavior would be similar to string substitution in php.</p>
  
  <pre><code>class Formatter(string.Formatter):
    def get_value(self,key,args,kwargs):
      try:
          if hasattr(key,"__mod__"):
              return args[key]
          else:
              return kwargs[key]
      except:
          return ""
  </code></pre>
  
  <p>This seems to provide the desired behavior.</p>