In Python, given the string\'int\', how can I get the type int? Using getattr(current_module, \'int\') doesn\'t work.
\'int\'
int
getattr(current_module, \'int\')
With this sort of thing, if you're expecting a limited set of types, you should use a dictionary to map the names to the actual type.
type_dict = { 'int': int, 'str': str, 'list': list } >>> type_dict['int']('5') 5