title: Adapt the formating pattern of a string if the last variable is an empty string
body: <p>I have a class that has multiple string patterns as class attributes.
  The patterns are later used to create strings.</p>
  <pre><code>class Main:
  
   pattern_for_a = &quot;{} {} {}&quot;
   pattern_for_b = &quot;{} {}-{}&quot;
   pattern_for_c = &quot;{}-{} {}&quot;
  ......................
  
   def do_a(*args, **kwargs):
     ............
     c = pattern_for_a.format(a1,a2,r)
  </code></pre>
  <p>This class have multiple subclasses which in some cases overwrites the patterns.Ex:</p>
  <pre><code>class B(Main):
  
   pattern_for_a = &quot;{}:{} {}&quot;
   pattern_for_b = &quot;{}-{}{}&quot;
   pattern_for_c = &quot;{}{} {}&quot;
  </code></pre>
  <p>This works well when all 3 variables have a real value. But there are cases, when the
  last variables is and empty string. In this special case the separator needs also to be removed.</p>
  <p>Example:</p>
  <pre><code>pattern_for_a = &quot;{}:{}-{}&quot;
  a=&quot;x&quot; b=&quot;y&quot; c=&quot;z&quot;
  Result: &quot;x:y-z&quot;
  </code></pre>
  <pre><code>pattern_for_a = &quot;{}:{}-{}&quot;
  a=&quot;x&quot; b=&quot;y&quot; c=&quot;&quot;
  Result: &quot;x:y-&quot;
  </code></pre>
  <p>The result contains also the separator <code>-</code>(in this case, the separator can be any char/string), and I want to be <code>x:y</code></p>
  <p>I can duplicate the patterns to have a set with all 3 variables available, and a separate set of patterns for when the last variable is just empty string and combine with <code>if else</code> conditions or just conditions to solve it.</p>
  <p>But because I have multiple patterns and need to check in multiple places I don't think the solution is optimal.</p>
  <p>I'm looking for a solution to solve it without using duplicate patterns and many <code>ifs</code>. Needs to work in python2.7 and 3.*.</p>