Is there an easy and obvious way to convert a string to a number of whatever type it looks like as a string, in other words I'd like to retain its type, whether it looks like int, float or complex and convert from string to number. This would be handy for example when reading data from text file. Usually conversion is made from string to a certain type of number for example a=int('2.2'). The downside of this is that 2.2 is not int and it will be cut to 2. Is there an easy and obvious way to let the code decide which type of number it is and convert to that type?
A similar question How do I parse a string to float or int in Python is a basic question of how to convert to int or float. My question went further and asked the code to decide which type of number it is.
A similar question How can I convert a string to either int or float with priority of int is a little hard to understand what the questions is, and the accepted answer does not cover my case.