Skip to content

Instantly share code, notes, and snippets.

@David256
Created August 18, 2019 18:28
Show Gist options
  • Save David256/b8954add382b91643f83f8c072ebd327 to your computer and use it in GitHub Desktop.
Save David256/b8954add382b91643f83f8c072ebd327 to your computer and use it in GitHub Desktop.
Una simple clase python para administrar acciones.
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import warnings
class Action(object):
"""Una acción"""
def __init__(self):
super(Action, self).__init__()
self.to_do = None
self.errors = list()
self.warnings = list()
def __call__(self, *args, **kwargs):
if not self.to_do:
warnings.warn("No se ha registrado una acción")
return False
self.to_do(self, *args, **kwargs)
return True
def register(self, function):
self.to_do = function
return function
def is_success(self):
if len(self.errors):
return False
else:
return True
if __name__ == '__main__':
action = Action()
@action.register
def stuff(self, value, name):
print("Action is called")
print("Action is doing thing...")
print("value:", value)
print("name:", name)
print("Action was called.")
self.errors.append("Error interno")
self.warnings.append("No se ha pasado parámetros")
action(56, "lel")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment