用于简单信息提取的python脚本



我有以下形式的数据:

Overall evaluation: 2
Invite to interview: 3
Strength or novelty of the idea (1): 3
Strength or novelty of the idea (2): 3
Strength or novelty of the idea (3): 4
Use or provision of open data (1): 3
Use or provision of open data (2): 2
"Open by default" (1): 3
"Open by default" (2): 2
Value proposition and potential scale (1): 3
Value proposition and potential scale (2): 2
Market opportunity and timing (1): 3
Market opportunity and timing (2): 2
Triple bottom line impact (1): 3
Triple bottom line impact (2): 2
Triple bottom line impact (3): 3
Knowledge and skills of the team (1): 2
Knowledge and skills of the team (2): 4
Capacity to realise the idea (1): 3
Capacity to realise the idea (2): 2
Capacity to realise the idea (3): 3
Appropriateness of the budget to realise the idea: 2

我想呈现如下:

=2+3+3+3+4+3+2+3+2+3+2+3+2+3+2+3+2+4+3+2+3+2

据我所知,Python对于这种愚蠢的任务来说非常强大,但我对语法不太熟悉,实现这一目标的最佳方法是什么?

也许类似于:

#create an array
#array = "="
f = open('data.txt', 'r')
for line in f:
    #number = grab that number off the end with some kind of regex
    #array.append(number + "+")

是否可以在python shell中运行此程序并输入数据,然后获取结果?

with open('data.txt', 'r') as f:
    for line in f:
        number = int(line.split(':')[1])
        array.append(number)
print '+'.join(array)

基本上,使用split函数获取数字,然后根据需要打印。请注意错误处理,以检查它是否是整数,或者行是否有:或不是

不确定shell是什么意思,但可以创建一个函数,只需调用一个函数:

最新更新