Advertisement
rfmonk

descriptors.py

Sep 6th, 2014
304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.43 KB | None | 0 0
  1. #! /usr/bin/env python
  2. """
  3. "Descriptors look weird. They're attached to the class and the methods
  4. have a funky signature."
  5.  
  6. This is from a talk given by a hacker at twitter
  7. This is for python 3 world
  8.  
  9. """
  10. class MyDescriptor(object):
  11.     def __get__(self, obj, type):
  12.         print self, obj, type
  13.     def __set__(self, obj, val):
  14.         print "Got %s" % val
  15.  
  16. class Myclass(object):
  17.     x = MyDescriptor()  # Attached at class definition time!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement