This is a problem I am facing for a data pipeline project. I have 2 data sources. One contains all the user data, the other contains meta data of what all columns we have to process from the user data to output.
So python is good with dynamic type casting, like if I say
a = float
b = "25.123"
c = a(b)
print(c)
>> 25.123
This is what I want to do, I want to dynamically type cast values in order to process them correctly. The type is retrieved from the meta-data data source. The problem is when I do a django model query on the meta-data, I get unicode objects.
a = model.objects.filter(id = 'id') # get the type variable from the meta-data
a = a[0]['type']
print(a)
>> u'float'
a("123.123")
>> TypeError: 'unicode' object is not callable
How do I convert this u'float' to float ? Does this approach have any better alternatives ? I checked out this, but it does not work
Open to all suggestions