我有以下形式的數據: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 +'+' –
啊!大!好主意。拉屎。有時我真的很短視。 –