I've read a lot of question regarding this but couldn't find any with str.
I got a long str consisting 16 bytes of name followed by 4 bytes of number and repeated for N number of people. Example as below :
*edit : 1)string is msg
2)added mike into intended output
msg = 'George\0\0\0\0\0\0\0\0\0\0' + '0095' + 'Mikeeeeeeeeeeee\0' + '0100' + 'Kelly\0\0\0\0\0\0\0\0\0\0\0' + '0000'
And now I need to store these data into json object. I've tried loop but it always rewrites the stored data before. I want something that works as below but for a lot longer string since writing msg[start:end] for every data is completely retarded.
data = {}
data[msg[0:16]] = {
"marks" : msg[16:20]
}
data[msg[20:36]] = {
"marks" : msg[36:40]
}
data[msg[40:56]] = {
"marks" : msg[56:60]
}
intended output:
{
"George\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000": {
"marks": "0095"
},
"Kelly\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000": {
"marks": "0000"
},
"Mikeeeeeeeeeeee\u0000": {
"marks": "0100"
}
}
Thanks
stringvariable comprised of some chunks of text and then you are working withmsgvariable. Show themsgvalueMikeein the msg string you have ?