SHARE
TWEET

Untitled

a guest Apr 24th, 2014 278 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/python
  2.  
  3. class X:
  4.   def fn1(self):
  5.     print("fn1")
  6.  
  7.   def fn2():
  8.     print("fn2")
  9.  
  10.   def __init__(self):
  11.     self.value = 99
  12.  
  13.  
  14. x = X()   # OK
  15. x.fn1()   # OK
  16. X.fn1(x)  # OK
  17. #X.fn1()  # TypeError: fn1() missing 1 required positional argument: 'self'
  18. #x.fn2()  # TypeError: fn2() takes 0 positional arguments but 1 was given
  19. X.fn2()   # OK in 3.2, 2.7: TypeError: unbound method fn2() must be called with X instance as first argument (got nothing instead)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top