In python, define a type, then cast to that type
In support of some legacy code, I have to read a text file and parse it for operators like x=102
and file=foo.dat
, which can be used to overwrite the default values. Note that the second does not exist file='foo.dat'
; these are not python instructions, but they are close.
Now I can get the type
default object, so I know what x
must be int and file
must be str. So, I need a way to cast the right side to this type. I would like to do this programmatically, so that I can name one simple default setting function. In particular, I would rather not iterate over all the built-in types. Is it possible?