0

my data is coming from subprocess and on the output i am receiving :

sample:

helo, aawe.adam , by the w,: 12.1:\r\n . heesa1.\r\n,b'asdasd',nme.AAAA.\r\n

type=<class 'bytes'>

i want to strip it in one line and then extract only barts between two characters, in this example . (dot)

expected result:

adam , by the w,: 12
1:
heesa1
,b'asdasd',nme
AAAA

I've also tried this method: Extracting text between two strings

but i am receiving errors : TypeError: cannot use a string pattern on a bytes-like object

thanks in advice `

2
  • What have you tried to solve the problem? Commented Jun 21, 2019 at 11:36
  • Did you try to convert bytes to string? Commented Jun 21, 2019 at 11:37

2 Answers 2

1

You need to decode the bytes for this to work. Try this:

output = b'helo, aawe.adam , by the w,: 12.1:\r\n . heesa1.\r\n,b'asdasd',nme.AAAA.\r\n'
str = output.decode("utf-8")

Then you can try to extract the data as you have before.

Sign up to request clarification or add additional context in comments.

1 Comment

yeaa right, thats it! then i can convert output to dataframe and i will receive all required lines, that was so simple, thanks
0
>>> o = b"helo, aawe.adam , by the w,: 12.1:\r\n . heesa1.\r\n,b'asdasd',nme.AAAA.\r\n"
>>> o.split(b".")
[b'helo, aawe', b'adam , by the w,: 12', b'1:\r\n ', b' heesa1', b"\r\n,b'asdasd',nme", b'AAAA', b'\r\n']

string split should help you by ignoring first and last item in the splited list.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.