title: Python Reflection and Type Conversion
body: <p>In Python, functions like str(), int(), float(), etc. are generally used to perform type conversions.  However, these require you to know at development time what type you want to convert to.  A subproblem of some Python code I'm trying to write is as follows:</p>
  
  <p>Given two variables, <code>foo</code> and <code>bar</code>, find the type of <code>foo</code>.  (It is not known at development time, as this is generic code.)  Then, attempt to convert <code>bar</code> to whatever type <code>foo</code> is.  If this cannot be done, throw an exception.</p>
  
  <p>For example, let's say you call the function that does this <code>conv</code>.  Its signature would look like</p>
  
  <pre><code>def conv(foo, bar) :
      # Do stuff.
  </code></pre>
  
  <p>It would be called something like:</p>
  
  <pre><code>result = conv(3.14, "2.718")  # result is now 2.718, as a float.
  </code></pre>