Created
September 7, 2015 22:46
-
-
Save abevieiramota/17f7d1ca0dc044118dd0 to your computer and use it in GitHub Desktop.
calcula soma de valores em um arquivo com estrutura de crtl c de uma tabela de despesas do fcpc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import sys | |
if __name__ == '__main__': | |
filepath = sys.argv[1] | |
f = open(filepath) | |
c = re.compile(r'R\$ (.*)$') | |
lines = f.readlines() | |
f.close() | |
valores = [c.findall(line)[0] for line in lines] | |
# remove pontos e converte para float | |
valores = [valor.replace('.', '') for valor in valores] | |
valores = [valor.replace(',', '.') for valor in valores] | |
valores = [float(valor) for valor in valores] | |
print sum(valores), "reais" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment