如何在python中读取某个字符到某个字符的每一行?

时间:2016-06-20 20:49:17

标签: python-3.x

我有一个文本文件(.txt):

1.  getChannelI32EnumAP ("_unnamedTask<67>", "", ChanType, Analog Input, "")
Process ID: 0x00001978         Thread ID: 0x000016C4
Start Time: 16:32:37.450       Call Duration 00:00:00.000
Status: 0

2.  DAQReadNChanNSamp1DWfm ("_unnamedTask<67>", 720, 10, 0.001, {-10.4392,-10.4392,...}, 0.001, {-0.911365,-0.916462,...}, "")
Process ID: 0x00001978         Thread ID: 0x000016C4
Start Time: 16:32:37.450       Call Duration 00:00:00.719
Status: 0

3.  getChannelI32EnumAP ("_unnamedTask<67>", "", ChanType, Analog Input, "")
Process ID: 0x00001978         Thread ID: 0x000016C4
Start Time: 16:32:38.169       Call Duration 00:00:00.000
Status: 0

4.  DAQReadNChanNSamp1DWfm ("_unnamedTask<67>", 720, 10, 0.001, {-10.4392,-10.4392,...}, 0.001, {-0.931751,-0.926655,...}, "")
Process ID: 0x00001978         Thread ID: 0x000016C4
Start Time: 16:32:38.169       Call Duration 00:00:00.721
Status: 0

5.  getChannelI32EnumAP ("_unnamedTask<67>", "", ChanType, Analog Input, "")
Process ID: 0x00001978         Thread ID: 0x000016C4
Start Time: 16:32:38.890       Call Duration 00:00:00.000
Status: 0

6.  DAQReadNChanNSamp1DWfm ("_unnamedTask<67>", 720, 10, 0.001, {-10.4392,-10.4392,...}, 0.001, {-0.941944,-0.941944,...}, "")
Process ID: 0x00001978         Thread ID: 0x000016C4
Start Time: 16:32:38.890       Call Duration 00:00:00.719
Status: 0

7.  getChannelI32EnumAP ("_unnamedTask<67>", "", ChanType, Analog Input, "")
Process ID: 0x00001978         Thread ID: 0x000016C4
Start Time: 16:32:39.609       Call Duration 00:00:00.000

现在我要读的是每个{}块中每个进程的第一个值,例如在编号为2的进程中我想从{-10.4392,-10.4392,...}读取-10.4392并将其存储到列表和来自同一行我也想从{-0.911365,-0.916462,...}读取-0.911365并将其存储到单独的列表中。每个进程都要遵循此模式。如何在python 3中做到这一点。

1 个答案:

答案 0 :(得分:1)

使用正则表达式将一行拆分为{}块;将每个块的内容分成,并抓住第一个。适用于python 2或3。