Why should i use python if i can use java

Tim Peters tim.one at home.com
Sun Jun 17 19:43:48 EDT 2001


[Martijn Faassen]
> ...
> Python doesn't really do any type checking for class instances; it
> checks whether there is a method that is of the right name and has
> the right amount of arguments somewhere on the instance or its
> superclasses, and calls it if so.  There is no 'is this the expected
> class?' check anywhere, not even at runtime.

If I do

    instance.xyz()

and it succeeds, then xyz is necessarily known to instance's class (whether
directly or via a base class).  What else is there *to* check in that case?

Try fooling it instead:

class A:
    def xyz(self):
        print "A.xyz"

class B:
    def xyz(self):
        print "B.xyz"

a = A()
B.xyz(a)

and you'll discover that Python refuses to run B.xyz() with an instance of
A, even though A has a method of the same name and signature:  "is this the
expected class?" checks are done at runtime.





More information about the Python-list mailing list