Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

Is there any advantage in using a Python class

By: a guest on Feb 26th, 2012  |  syntax: None  |  size: 0.45 KB  |  views: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class Something(object):
  2.  
  3.     @staticmethod
  4.     def foo(x):
  5.         return x + 5
  6.  
  7.     @staticmethod
  8.     def bar(x, y):
  9.         return y + 5 * x
  10.        
  11. # something.py
  12.  
  13. def foo(x):
  14.     return x + 5
  15.  
  16. def bar(x, y):
  17.     return y + 5 * x
  18.        
  19. import something
  20. print something.foo(10)
  21. print something.bar(12, 14)
  22.        
  23. class Something(object):
  24.     def foo(self, x):
  25.         return x + 5
  26.  
  27.     def bar(self, x, y):
  28.         return y + 5 * self.foo(x)
  29.  
  30. something = Something()