title: Getting key arguments from prepared string
body: <p>I have a prepared string, e.g. <code>my_string = 'My name is {name}.'</code></p>
  
  <p>and I have dictionary of kwargs, such as:</p>
  
  <pre><code>format_kwargs = {
      'name': 'John',
      ...
  }
  </code></pre>
  
  <p>So that I can format the string in this manner: <code>my_string.format(**format_kwargs)</code></p>
  
  <p>That is all good. The problem is that I want to determine what keys are in the string, so that I do not calculate the kwargs needlessly. That is, I have a set of keywords used in these strings by default, but not all of them are used in all strings. They are basically regular messages shown to user, such as '{name}, you account was successfully created!'.</p>
  
  <p>I want to do something like:</p>
  
  <pre><code>format_kwargs = {}
  
  if 'name' in &lt;my_string.keys&gt;:
      format_kwargs['name'] = self.get_user().name
  if '...' in &lt;my_string.keys&gt;:
      format_kwargs['...'] = some_method_...()
  
  my_string.format(**format_kwargs)
  </code></pre>
  
  <p>How do I retrieve the keys?</p>
  
  <p>EDIT:</p>
  
  <p>a simple <code>if 'name' in my_string</code> does not work because that would also match something like <code>{parent_name}</code> or <code>'The name change was not successful.'</code></p>