Extract data from result | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Extract data from result

b'SerialNumber \r\r\nINA308X8BS \r\r\n\r\r\n' This is my result from my python code and need to extract INA308X8BS from above line, result may varies from INA308X8BS to other value. Please someone help

6th May 2020, 4:03 PM
Raj Charan
4 Answers
+ 6
Why is your "string" signed as a byte sequence? Is there any need for that? Here is a code that should do the job: inp = 'SerialNumber \r\r\nINA308X8BS \r\r\n\r\r\n' res = [i for i in inp if i.isalnum()] print(''.join(res).replace('SerialNumber',''))
6th May 2020, 5:28 PM
Lothar
Lothar - avatar
+ 1
I dunno what it is but it resulted in 101 a=b'SerialNumber \r\r\nINA308X8BS \r\r\n\r\r\n' for i,j in enumerate(a.split()): if j==b'INA308X8BS': print(a[i]) that 101 is index number for b'INA308X8BX' ,I thought it should be 1
6th May 2020, 4:09 PM
Abhay
Abhay - avatar
+ 1
Lol I really forgot it could be extracted that easily I went the other way ,
6th May 2020, 4:14 PM
Abhay
Abhay - avatar
+ 1
Thank you all
6th May 2020, 5:29 PM
Raj Charan