Guest User

Untitled

a guest
Oct 12th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. " Python 2 version "
  2.  
  3. class MyMetaclass(type):
  4.  
  5. def __new__(cls, name, bases, dct):
  6.  
  7. attrs = ((name, value) for name, value in dct.items() if not name.startswith('__'))
  8. attrs = dict(("__" + name.upper(), value) for name, value in attrs)
  9.  
  10. return super(MyMetaclass, cls).__new__(cls, name, bases, attrs)
  11.  
  12.  
  13. class BaseClass(object):
  14. __metaclass__ = MyMetaclass
  15.  
  16. class Banana(BaseClass):
  17. v = 10
  18.  
  19.  
  20. if __name__ == '__main__':
  21.  
  22. kk = Banana()
  23.  
  24. try:
  25. print "kk.v is: %s" % kk.v
  26. except AttributeError:
  27. print "There is not a 'kk.v' here"
Add Comment
Please, Sign In to add comment