title: replacing a variable in multiple places in a string
body: <p>I have a string that I want to put one variable in multiple places in it:</p>
  
  <pre><code>query_1 ='SELECT distinct ?a\
          WHERE { ?a rno:end_at ?b.\
          ?b rdf:type rno:Node; rno:is_extent_of ?x.\
          ?x rno:builds %s. %s a rno:Roundabout.\
          FILTER(NOT EXISTS {?a rno:builds %s})} ORDER BY ?a'%(ref_RaURI, ref_RaURI,ref_RaURI)
      print query_1
  </code></pre>
  
  <p>the above replacement works but I don't want to repeat the variable ref_RaURI, so I tried the following:</p>
  
  <pre><code>query_1 ='SELECT distinct ?a\
          WHERE { ?a rno:end_at ?b.\
          ?b rdf:type rno:Node; rno:is_extent_of ?x.\
          ?x rno:builds {0}. {0} a rno:Roundabout.\
          FILTER(NOT EXISTS {?a rno:builds {0}})} ORDER BY ?a'.format(ref_RaURI)
      print query_1
  </code></pre>
  
  <p>this one is returning:</p>
  
  <pre><code>    FILTER(NOT EXISTS {?a rno:builds {0}})} ORDER BY ?a'.format(ref_RaURI)
  KeyError: ' ?a rno'
  </code></pre>
  
  <p>Using dictionary:</p>
  
  <pre><code>        query_1 ="SELECT distinct ?a\
          WHERE { ?a rno:end_at ?b.\
          ?b rdf:type rno:Node; rno:is_extent_of ?x.\
          ?x rno:builds %(s). %(s) a rno:Roundabout.\
          FILTER(NOT EXISTS {?a rno:builds %(s)})} ORDER BY ?a"%{'s':ref_RaURI}
      print query_1
  </code></pre>
  
  <p>returns:</p>
  
  <pre><code>    FILTER(NOT EXISTS {?a rno:builds %(s)})} ORDER BY ?a"%{'s':ref_RaURI}
  ValueError: unsupported format character ' ' (0x20) at index 140
  </code></pre>
  
  <p>Is there any way to make it work?</p>