tzot

Checking operator attrgetter in replaced __dict__

Jan 10th, 2013
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.50 KB | None | 0 0
  1. Python 2.7.3 (default, Aug  1 2012, 05:16:07)
  2. [GCC 4.6.3] on linux2
  3. Type "copyright", "credits" or "license()" for more information.
  4. ==== No Subprocess ====
  5. >>> class A(object):
  6.     def __init__(self, **kwargs):
  7.         self.__dict__= kwargs
  8.  
  9.        
  10. >>> class B(object):
  11.     def __init__(self, **kwargs):
  12.         self.__dict__.update(kwargs)
  13.  
  14.        
  15. >>> a=[A(code=1), A(code=2)]
  16. >>> b=[B(code=1), B(code=2)]
  17. >>> import operator
  18. >>> a.sort(key=operator.attrgetter("code"))
  19. >>> b.sort(key=operator.attrgetter("code"))
  20. >>>
Advertisement
Add Comment
Please, Sign In to add comment