title: How to insert a variable in a SPARQL query with triple-quotation (""") in SPARQLWrapper (Jupyter notebook)
body: <p>Very simple question about inserting a varaible in a SPARQL query in the Wrapper library. Example below in a Jupyter notebook, I defined a variable <code>'q'</code> outside SPARQL query, and would like to use it within a SPARQL query. I could not find out how to escape triple-quotation (<code>&quot;&quot;&quot;</code>). Quick help would be appreciated. Many thanks!</p>
  <pre><code>!pip install SPARQLWrapper
  from SPARQLWrapper import SPARQLWrapper, JSON, XML
  
  q = '&lt;http://data.europeana.eu/item/08517/3395FCFC5812F76279634269BE601072BF09183B&gt;'
  query_content = &quot;&quot;&quot;
  select *
  where {
  ?providerProxy ore:proxyFor 'q' ; ?p ?o 
  }
  &quot;&quot;&quot;
  
  query = prefix + query_content
  sparql.setQuery(query)
  sparql.setReturnFormat(JSON)
  results = sparql.query().convert()
  print(results)
  print('------')
  for result in results[&quot;results&quot;][&quot;bindings&quot;]:
    p = result[&quot;p&quot;][&quot;value&quot;]
    o = result[&quot;o&quot;][&quot;value&quot;]
    print(p + &quot; : &quot; + o)
  </code></pre>
  <p>Somehow the following method (.format) does not work.</p>
  <pre><code>query_content = &quot;&quot;&quot;
  select ?providerProxy
  where {
  ?providerProxy ore:proxyFor {var}
  }
  LIMIT 100
  &quot;&quot;&quot;.format(var = '&lt;http://data.europeana.eu/item/08517/3395FCFC5812F76279634269BE601072BF09183B&gt;')
  
  query = prefix + query_content
  sparql.setQuery(query)
  sparql.setReturnFormat(JSON)
  </code></pre>
  <p>Error looks like:</p>
  <pre><code>HTTPError                                 Traceback (most recent call last)
  /usr/local/lib/python3.7/dist-packages/SPARQLWrapper/Wrapper.py in _query(self)
      925             else:
  --&gt; 926                 response = urlopener(request)
      927             return response, self.returnFormat
  
  HTTPError: HTTP Error 400: Bad Request
  During handling of the above exception, another exception occurred:
  
  QueryBadFormed                            Traceback (most recent call last)
  /usr/local/lib/python3.7/dist-packages/SPARQLWrapper/Wrapper.py in _query(self)
      928         except urllib.error.HTTPError as e:
      929             if e.code == 400:
  --&gt; 930                 raise QueryBadFormed(e.read())
      931             elif e.code == 404:
      932                 raise EndPointNotFound(e.read())
  
  QueryBadFormed: QueryBadFormed: A bad request has been sent to the endpoint: probably the SPARQL query is badly formed. 
      results = sparql.query().convert()
      print(results)
      print('------')
  </code></pre>
  <p>Similarly, f&quot;&quot;&quot; {} &quot;&quot;&quot; method does not work:</p>
  <pre><code>var = '&lt;http://data.europeana.eu/item/08517/3395FCFC5812F76279634269BE601072BF09183B&gt;'
  query_content = f&quot;&quot;&quot;
  select ?providerProxy
  where {
  ?providerProxy ore:proxyFor {var}
  LIMIT 100
  &quot;&quot;&quot;
  </code></pre>
  <p>returns error:</p>
  <pre><code>  File &quot;&lt;fstring&gt;&quot;, line 2
      ?providerProxy ore)
      ^
  SyntaxError: invalid syntax
  </code></pre>