[ create a new paste ] login | about

Link: http://codepad.org/pM4JGbyf    [ raw code | output | fork ]

Python, pasted on Dec 15:
def func(obj, num):
    if(num == 0):
        obj.func0()
    else:
        obj.func1()

class MyClass0:
    def func0(self):
        print "MyClass0: func0"
    def func1(self):
        print "MyClass0: func1"

class MyClass1:
    def func0(self):
        print "MyClass1: func0"

x = MyClass0()
y = MyClass1()

func(x, 0)
func(x, 1)

func(y, 0)
func(y, 1)


Output:
1
2
3
4
5
6
7
8
9
MyClass0: func0
MyClass0: func1
MyClass1: func0
Traceback (most recent call last):
  Line 24, in <module>
    func(y, 1)
  Line 5, in func
    obj.func1()
AttributeError: MyClass1 instance has no attribute 'func1'


Create a new paste based on this one


Comments: