Hello all…good day…please help on how to strip byte string as below:
input : b'\x081F304984\x0843501'
output : 1F304984
thanks a lot
Hello all…good day…please help on how to strip byte string as below:
input : b'\x081F304984\x0843501'
output : 1F304984
thanks a lot
What is the rule that tells you which bytes to take?
Thanks for the reply…but sorry i dont understand your question…am not expert yet in python…thanks
It is not a python question it is question about your data.
How do you want you data cleaned up?
Remove all bytes that are less then 14? Only allow 1 to 9?
Hello Barry…
input : b'\x081F304984\x0843501'
*this input type is byte*
From the input...i want to take out values as expected below
expected output : 1F304984 (maybe in type string also fine)
The data is a list of numbers separated by TABs? TAB is 0x08 byte.
Does this work for you?
numbers = input.split()
print(numbers)
(Edited after remark from Chris)
split()
doesn’t split on \x08
:
>>> input = b'\x081F304984\x0843501'
>>> input.split()
[b'\x081F304984\x0843501']
To split on \x08
, use:
>>> input.split(b'\x08')
[b'', b'1F304984', b'43501']
Or, if you want to end up with normal str
type:
>>> input.decode().split('\x08')
['', '1F304984', '43501']
split()
does split on tabs, but those aren’t tabs, those are backspaces. Tab is 9
That’s not the question.
The question is: how do you know that those are the values that should be taken out?
If the output had different values instead, how would you know they are wrong?
Not quite:
>>> b'\t'[0]
9
8
instead corresponds to a backspace character in ASCII:
>>> b'\b'[0]
8
which is not used for whitespace splitting.