I want to dynamically read from the command line and convert the input to the right format. Therefore I have to determien the required type and instantiate such an object. Due input is str I have to convert the input correctly.
Here is an example what I want to do in pseudocode. If TypeOf fails it should raise an exception, maybe ValueError.
required_foo_type = 3.0
foo_input = Input("Enter foo: ")
bar = new TypeOf(required_foo_type, foo_input)
How can I do that in python?
1 Answer