我有以下形式的数据: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中运行本程序和数据反馈,然后抓出结果?
如果你知道你的数字总是在行的最后一位是单个数字,那么'line [-1]'会这样做,以提示使用'line.split(“:”)' – shuttle87
'您。否则''re.search('。* \ d +,line)'会做同样的事情。另外,我会建议(如果你打算在第一个总结它)初始化数组为'array = []'然后调用'.append(number)'然后'sum(array)'。一个字符串不能附加上,除非你做'array + = number +'+' –
啊!大!好主意。拉屎。有时我真的很短视。 –