I need to be pointed in the right direction for this problem I’m working on:
Let’s say I’m reading output from a C program as follows:
while True:
ln = p.stdout.readline()
if '' == ln:
break
#do stuff here with ln
And my output looks like this line for line:
TrnIq: Thread on CPU 37
TrnIq: Thread on CPU 37 but will be moved to CPU 44
IP-Thread on CPU 33
FANOUT Thread on CPU 37
Filter-Thread on CPU 38 but will be moved to CPU 51
TRN TMR Test 2 Supervisor Thread on CPU 34
HomographyWarp Traking Thread[0] on CPU 26
I want to capture “TrnIq: Thread on” and “37” as 2 separate variables: a string and a number from output “TrnIq: Thread on CPU 37”.
Its pretty well the same for the other lines to, for example capture “HomographyWarp Traking Thread[0] on” and the # “26” from “HomographyWarp Traking Thread[0] on CPU 26”.
The only real challenge is for lines like this: “Filter-Thread on CPU 38 but will be moved to CPU 51” on this line I need “Filer-Thread” and the # “51” not the first # “38”.
Python has so many different ways to do this I dont even know where to start!
Thanks in advance!
regex seems like overkill to me here. [Disclaimer: I don’t like regular expressions, but do like Python, so where possible I write in Python, and don’t write regular expressions. For reasons I’ve never fully understood this is considered surprising.]
gives
and I don’t think I need to translate any of this code into English.