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 `

sygneto
  • 1,761
  • 1
  • 13
  • 26

2 Answers2

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.

Nick
  • 3,454
  • 6
  • 33
  • 56
  • yeaa right, thats it! then i can convert output to dataframe and i will receive all required lines, that was so simple, thanks – sygneto Jun 21 '19 at 11:46
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.

Sunil Kumar
  • 186
  • 3
  • 12