title: Python: Determine String Formatting With a boolean?
body: <p>I'm new to Python and I am wondering what the best way is to format a string with the parts inserted determined by booleans.</p>
  
  <p>I have a long html form string that can have error messages. I only want to show error messages for those parts of the form that did not validate correctly:</p>
  
  <pre><code>   form = """Signup
      &lt;form method="post"&gt;
        &lt;table&gt;
          &lt;tr&gt;
            &lt;td class="label"&gt;
              Username
            &lt;/td&gt;
            &lt;td&gt;
              &lt;input type="text" name="username" value="%(un)s"&gt;
            &lt;/td&gt;
            &lt;td class="error"&gt; 
                %(un_err)s
            &lt;/td&gt;
          &lt;/tr&gt;
         ............
  
      &lt;/form&gt;"""
  </code></pre>
  
  <p>When I am processing the post call I have this:</p>
  
  <pre><code>self.response.out.write(form % {"un": username, "pw": password, "pwv": validate, "email": email, "un_err": "", "pw_err": "", "verify_err": "", "email_err": ""})
  </code></pre>
  
  <p>Each "..._err" message is determined by a separate boolean, for example, if valid_username is false then the output should be:</p>
  
  <pre><code>self.response.out.write(form % {"un": username, "pw": password, "pwv": validate, "email": email, "un_err": "This is not a valid username", "pw_err": "", "verify_err": "", "email_err": ""})
  </code></pre>
  
  <p>Is there a nice way to do this?</p>