But if I want to converte only 1 item in list?
for example item on 4 place only?
for example item on 4 place only?
def CutData(FullData, StartByte, length=1): StartByte = StartByte - 1 EndByte = StartByte + length print(f'full data is {FullData}') Data_Byte = FullData.split(' ') print(f'Full Data_Byte is {Data_Byte}') Wanted_Data = str(Data_Byte[StartByte:EndByte]) print(type(Wanted_Data)) return Wanted_Data if PID == "1E491DD0": Speed= (CutData(Data, 4, 1)) print (str(type(Speed)) + " " + Speed)I get
full data is e5 a9 5c 7e b2 ff 02 00 Full Data_Byte is ['e5', 'a9', '5c', '7e', 'b2', 'ff', '02', '00'] <class 'str'> <class 'str'> ['b2']when I do the same thing on console , it's working
>>> Test_List = ['12', '34', 'AA', 'F2'] >>> type(Test_List) <class 'list'> >>> type(Test_List[2]) <class 'str'> >>> y = int(Test_List[2], 16) >>> print(y) 170also if I take your example - it's working (same class - both of them are strings)
>>> spam = bytearray(b'0P\x14}\x04\xf8\xff3') >>> data = [f"{byte:02x}" for byte in spam] >>> print(data) ['30', '50', '14', '7d', '04', 'f8', 'ff', '33'] >>> type(data[2]) <class 'str'> >>> y = int(data[2], 16) >>> print(y) 20Thanks ,