我有以下代码:
f = open('./dat.txt', 'r')
array = []
for line in f:
# if "1\t\"Overall evaluation" in line:
# words = line.split("1\t\"Overall evaluation")
# print words[0]
number = int(line.split(':')[1].strip('"\n'))
print number
这能够从我的数据中获取最后一个int,如下所示:
299 1 "Overall evaluation: 3
Invite to interview: 3
Strength or novelty of the idea (1): 4
Strength or novelty of the idea (2): 3
Strength or novelty of the idea (3): 3
Use or provision of open data (1): 4
Use or provision of open data (2): 3
""Open by default"" (1): 2
""Open by default"" (2): 3
Value proposition and potential scale (1): 4
Value proposition and potential scale (2): 2
Market opportunity and timing (1): 4
Market opportunity and timing (2): 4
Triple bottom line impact (1): 4
Triple bottom line impact (2): 2
Triple bottom line impact (3): 2
Knowledge and skills of the team (1): 3
Knowledge and skills of the team (2): 4
Capacity to realise the idea (1): 4
Capacity to realise the idea (2): 3
Capacity to realise the idea (3): 4
Appropriateness of the budget to realise the idea: 3"
299 2 "Overall evaluation: 3
Invite to interview: 3
Strength or novelty of the idea (1): 3
Strength or novelty of the idea (2): 2
Strength or novelty of the idea (3): 4
Use or provision of open data (1): 4
Use or provision of open data (2): 3
""Open by default"" (1): 3
""Open by default"" (2): 2
Value proposition and potential scale (1): 4
Value proposition and potential scale (2): 3
Market opportunity and timing (1): 4
Market opportunity and timing (2): 3
Triple bottom line impact (1): 3
Triple bottom line impact (2): 2
Triple bottom line impact (3): 1
Knowledge and skills of the team (1): 4
Knowledge and skills of the team (2): 4
Capacity to realise the idea (1): 4
Capacity to realise the idea (2): 4
Capacity to realise the idea (3): 4
Appropriateness of the budget to realise the idea: 2"
364 1 "Overall evaluation: 3
Invite to interview: 3
...
我还需要抓取"记录标识符"在上面的示例中,前两个实例为299
,下一个实例为364
。
上面注释掉的代码,如果我删除最后一行并使用它,如下:
f = open('./dat.txt', 'r')
array = []
for line in f:
if "1\t\"Overall evaluation" in line:
words = line.split("1\t\"Overall evaluation")
print words[0]
# number = int(line.split(':')[1].strip('"\n'))
# print number
可以获取记录标识符。
但是我把两者放在一起很麻烦。
理想情况下,我想要的是以下内容:
368
=2+3+3+3+4+3+2+3+2+3+2+3+2+3+2+3+2+4+3+2+3+2
=2+3+3+3+4+3+2+3+2+3+2+3+2+3+2+3+2+4+3+2+3+2
依此类推所有记录。
如何组合上述两个脚本组件来实现这一目标?
答案 0 :(得分:1)
正则表达是门票。你可以用两种模式做到这一点。像这样:
$output = '';
$command = 'c:\inetpub\wwwroot\mamobile\crexport -F c:\inetpub\wwwroot\mamobile\reports\customer.rpt -O c:\inetpub\wwwroot\mamobile\output\test.pdf -E pdf -S testdb';
exec($command, $output);
var_dump($output);
注意:最后一个print语句不是你的要求的一部分,但每当我调试regex时,我总是添加一些catchall来帮助调试坏的regex语句。一旦我直接得到我的图案,我就删除了它。