我需要指出在这个问题的正确方向查找多个字符串纪录我的工作:最佳方法在Python
比方说,我是从一个C程序读取输出如下:
while True:
ln = p.stdout.readline()
if '' == ln:
break
#do stuff here with ln
而且我的输出看起来像这行线:
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
我想捕捉“TrnIq:线程”和“37”作为两个独立的变量:一个字符串和一个数字从输出“TrnIq :在CPU上线程37" 。
对于其他行,例如捕获“HomographyWarp Traking Thread [0] on”和#“26”,来自“在CPU 26上的HomographyWarp Traking Thread [0]”,它相当不错。
唯一真正的挑战是这样的行:“在CPU 38上的过滤器线程,但将被移动到CPU 51”,我需要“Filer-Thread”和#“51”不是第一个#“ 38" 。
Python有很多不同的方法来做到这一点我甚至不知道从哪里开始!
在此先感谢!
“Thanks”for unaccaptance ... – 2012-07-24 20:15:10