given a list of python strings, how can I automatically convert them to their correct type? Meaning, if I have:
[\"hello\", \"3\", \"3.64\", \"-1\"]
<
This is not really an answer, but I wanted to point out how important this can be when you have a database of parameters with schema ID
, PAR
, VAL
. For instance:
ID PAR VAL
001 velocity '123.45'
001 name 'my_name'
001 date '18-dec-1978'
This schema is appropriate when you don't know how many parameters you need to store for a certain ID
. The disadvantage is precisely that the values in VAL
are all strings, and need to be converted to the correct data type on demand. You can do this by adding a fourth column to the schema, called TYPE
, or you can use any of the approaches proposed thus far.
Good question!
PS. The database schema is related to one of my previous questions.