fork download
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. DATA = {
  5. 'wall': (1,2,3),
  6. 'messages': (4,5,6),
  7. 'photos': (7,8,9),
  8. 'videos': (10,11,12),
  9. }
  10.  
  11. get = lambda name: DATA[name.replace('get_','')]
  12.  
  13. class VK(object):
  14. __all__ = ('get_wall', 'get_messages',
  15. 'get_photos', 'get_videos')
  16.  
  17. def __init__(self):
  18. self.x = 2
  19.  
  20. def __getattr__(self, name):
  21. if name in self.__all__:
  22. return lambda: get(name)
  23. else:
  24. return getattr(name)
  25.  
  26. def main():
  27. v = VK()
  28.  
  29. print v.get_photos()
  30. print v.get_wall()
  31. print v.x
  32.  
  33. if __name__ == '__main__':
  34. main()
Success #stdin #stdout 0.03s 6356KB
stdin
Standard input is empty
stdout
(7, 8, 9)
(1, 2, 3)
2