Oct-06-2020, 12:40 AM
Oct-06-2020, 01:12 AM
(Oct-06-2020, 12:40 AM)ridgerunnersjw Wrote: [ -> ]I have the following :
What is the best way to parse this to remove all and get 005 (middle term)?
Output:b'011;005;080;'
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)
Oct-06-2020, 01:28 AM
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)
Oct-06-2020, 02:06 AM
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.