Advertisement
Guest User

Untitled

a guest
Apr 28th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. from types import FunctionType
  2.  
  3. def log(func):
  4. def function(*args,**kwargs):
  5. with open("logfile","a") as f:
  6. f.writelines(func.__name__ + str(args) + " " + str(kwargs) + str(func(*args,**kwargs)) + "\n")
  7. return function
  8.  
  9. class loggermetaclass(type):
  10. def __new__(meta, classname,supers, classdict):
  11. for attr, attrval in classdict.items():
  12. if type(attrval) is FunctionType and attr[0] != "_" and attr[1] != "_":
  13. classdict[attr] = log(attrval)
  14. return type.__new__(meta,classname,supers,classdict)
  15.  
  16.  
  17. class logger():
  18.  
  19. __metaclass__ = loggermetaclass
  20.  
  21. def printint(self,k):
  22. return k
  23. def hello(self,string):
  24. return string
  25.  
  26. def __str__(self):
  27. with open("logfile", "r") as f:
  28. text = f.read()
  29. return text
  30.  
  31. class blogger(logger):
  32. def popk(self,o):
  33. return o
  34.  
  35.  
  36.  
  37.  
  38. m = blogger()
  39. m.popk(9)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement