I have a string byte
data = b'ra1,rb1,rc1\nra2,rb2,rc2\nra3,rb3,rc3\nra4,rb4,rc4' # No \n at the end
The result should be like
result = [
{"field1": "ra1", "field2": "rb1", "field3": "rc1"},
{"field1": "ra2", "field2": "rb2", "field3": "rc2"},
{"field1": "ra3", "field2": "rb3", "field3": "rc3"},
{"field1": "ra4", "field2": "rb4", "field3": "rc4"}
]
I tried
result = csv.DictReader(data, fieldnames=('field1', 'field2', 'field3'))
Please note that I'm not dealing with any CSV files here.
I know we need to pass file object as the first parameter to the above DictReader method to get the above result.
Is there any similar in-built method in python 3.6 to achieve my result?
Here I don't want to use loop since my data will be very huge.