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
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
#Exemplo de *args e **kwargs (argumentos ilimitados, nomeados e em qualquer ordem) | |
class Conta(): | |
#É precico passar o self para dentro dos métodos de instância | |
#O Python é bem explícito :) | |
def metodo(self, *args, **kwargs): | |
print args | |
print kwargs |
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
#Recebe a função soma como argumento (f = soma) | |
def meu_decorator(f): | |
#Escreve uma nova função | |
#nova_soma recebe os mesmos argumentos da soma (não precisa ser *args) | |
#Imagine que é uma nova versão da sua soma | |
def nova_soma(x,y): | |
#Executa algo antes | |
print 'iniciando nova soma' | |
f(x,y) #Chama a própria função soma (a soma externa) | |
#Executa algo depois |
NewerOlder