Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
parsing question
#1
I have the following :
Output:
b'011;005;080;'
What is the best way to parse this to remove all and get 005 (middle term)?
Reply
#2
(Oct-06-2020, 12:40 AM)ridgerunnersjw Wrote: I have the following :
Output:
b'011;005;080;'
What is the best way to parse this to remove all and get 005 (middle term)?

You can use regular expression as the example below:

import re
v_ent = "b'011;005;080;'"
v_sub = "005"
v_out = re.sub(r"b'011;005;080;'", v_sub, v_ent)
print(v_out)
Reply
#3
That seems to work quite well except my value that I gave is only an example and the three values are data read from an IC. They change. I need to be able to basically read then parse to get the inner 3 values...The following quasi works but it puts a newline after printing each value...I tried value.strip() but it doesn't seem to work

	def DataParser(self, parse_value):
		for value in parse_value:
			if (value == ':'):
				print ('\n')
			else:
				print (value)
Reply
#4
Output:
>>> b'011;005;080;'.split(b';')[1] b'005'
Though a more generic regular expression may be faster. You probably don't need that, but if you do it's worth the effort to read a basic tutorial on regexes.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  parsing question ridgerunnersjw 7 5,061 Oct-10-2020, 09:04 PM
Last Post: ridgerunnersjw
  string parsing question ( I think) diggee17 4 3,019 Jul-24-2019, 02:37 PM
Last Post: diggee17
  Parsing Large Numbers Question amyvaulhausen 5 3,344 Mar-24-2019, 08:46 AM
Last Post: samsonite

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020