Skip to content

Instantly share code, notes, and snippets.

@abevieiramota
Created September 7, 2015 22:46
Show Gist options
  • Save abevieiramota/17f7d1ca0dc044118dd0 to your computer and use it in GitHub Desktop.
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
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