In python, detect type, then cast to that type
<p>In support of some legacy code, I have to read a text file and parse it for statements like <code>x=102</code> and <code>file=foo.dat</code> that might be used to overwrite default values.  Note that the second one there is not <code>file='foo.dat'</code>; these aren't python statements, but they're close.</p>

<p>Now, I can get the <code>type</code> of the default object, so I know that <code>x</code> should be an int and <code>file</code> should be a str.  So, I need a way to cast the right-hand side to that type.  I'd like to do this programmatically, so that I can call a single, simple default-setting function.  In particular, I'd prefer to not have to loop over all the built-in types.  Is it possible?</p>
