title: how to convert a string into url in python
body: <p>I have a string with the following format: <code>foo://bar_baz</code>.<br />
  I need to encode the entire string to be URL friendly. Right now I am doing it like so (as most answers seem to point):</p>
  <pre><code>from urllib.parse import urlencode
  mydict = {'q': 'foo://bar_baz'}
  urlencode(mydic)
  </code></pre>
  <p>which returns:</p>
  <pre><code>'q=foo%3A%2F%2Fbar_baz'
  </code></pre>
  <p>I can use this without problem, but it seems counterintuitive / extra steps to have to define a dictionary, and assign a key (in this case <code>q</code>) that I will not be using.
  Moreover, I need to go through the step of properly parsing the output to remove the <code>q=</code>
  as I only need to encode the value for the key <code>q</code>. Spliting by <code>q=</code> could do it, but what if foo/bar/baz are actualy <code>fooq=</code> ? it might break stuff.</p>
  <p>I was hoping to do something like:</p>
  <pre><code># pass a string instead of a dict
  encoded_string = urlencode(&quot;foo://bar_baz&quot;)
  </code></pre>
  <p>but that of course raises error.</p>