Please help me to understand classes

Evan Simpson evan at tokenexchange.com
Tue Jun 29 22:00:14 CEST 1999


Your Pascal experience is showing <wink>.  While you can call a
parameterless function or procedure without parentheses in Pascal, Python
always requires them, since functions are first-class objects.

So when you write "a.druk", you are fetching the method "druk" from "a", but
then doing nothing with it.  You should write "a.druk()", which will call
the method with no parameters.

One reason for the required parentheses is the ability to do this:

f = a.druk  # get the method and make f refer to it.
f()  # call the method.

Johann Spies wrote in message ...
I have been playing around with python for some time now, but I am a
relative newbie as it is my hobby and normally I have very little time for
programming.  I am on leave now and want to write a program but I find
python a very difficult language to comprehend despite the fact that I
have a few years of experience in programming a language like Pascal.
Maybe it is because I have little experience in OOP.

Can somebody explain to me why the following program produces no output:
---------------------------------------------
class A:

    def druk():
        print 'Jy is in Class A'

class B:

    def druk():
        print 'Jy is in Class B'

a = A()
c = B()
c.druk
a.druk







More information about the Python-list mailing list