First, you cannot write a "universal" or "smart" conversion that magically handles anything.
Second, trying to summarize a string-to-data conversion in anything other than code never seems to work out well. So rather than write a string that names the conversion, just write the conversion.
Finally, trying to write a configuration file in a domain-specific language is silly. Just write Python code. It's not much more complicated than trying to parse some configuration file.
Is is possible or do i need to do some other stuff?
Don't waste time trying to create a "type file" that's not simply Python. It doesn't help. It is simpler to write the conversion as a Python function. You can import that function as if it was your "type file".
import datetime
def convert( row ):
return dict(
id= int(row['id']),
value= str(row['value']),
date= datetime.datetime.strptime(row['date],"%Y-%m-%d %H:%M:%S"),
)
That's all you have in your "type file"
Now you can read (and process) your input like this.
from type_file import convert
import csv
with open( "date", "rb" ) as source:
rdr= csv.DictReader( source )
for row in rdr:
useful_row= convert( row )
in many cases i do not know the number of columns or the data type before runtime
This means you are doomed.
You must have an actual definition the file content or you cannot do any processing.
"id","value","other value"
1,23507,3
You don't know if "23507" should be an integer, a string, a postal code, or a floating-point (which omitted the period), a duration (in days or seconds) or some other more complex thing. You can't hope and you can't guess.
After getting a definition, you need to write an explicit conversion function based on the actual definition.
After writing the conversion, you need to (a) test the conversion with a simple unit test, and (b) test the data to be sure it really converts.
Then you can process the file.