mytype = "int"
myvalue = "35"
my_int_val = mytype(myvalue)
This throws up -
TypeError: 'str' object is not callable
I can't seem to remember the way to do so. Any ideas?
Please note that I have to use "str", "int" instead of str or int (without quotes), because I am getting this value from somewhere else where it's being passed on as a string.
my_int_val = int(myvalue)str("35")to return an integer value?my_int_val = "int"("35"). The name of (a reference to) a type is not the same thing as the type itself. As types are first-class values in Python, you can definemytype = int, and the rest of your code will work as you expect.