Please help me to understand classes

Stidolph, David Stidolph
Tue Jun 29 22:05:22 CEST 1999


From: "Stidolph, David" <stidolph at origin.ea.com>

Finally, a simple question I can answer!

First of all, class methods like "druk" need to have a parameter declared in
them called self (or whatever you want to call it).  Secondly you need to
call the method with open/close parens:

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

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

a = A()
c = B()
c.druk()
Jy is in Class B
a.druk()
Jy is in Class A

I hope this helps,

David.


-----Original Message-----
From: Johann Spies [mailto:jhspies at futurenet.co.za]
Sent: Tuesday, June 29, 1999 2:04 PM
To: Python-poslys
Subject: Please help me to understand classes


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
---------------------------------------------


 --------------------------------------------------------------------------
| Johann Spies                                 Windsorlaan 19              |
| jhspies at futurenet.co.za                3201 Pietermaritzburg             |
| Tel/Faks Nr. +27 331-46-1310		       Suid-Afrika (South Africa)  |
 --------------------------------------------------------------------------

     "One thing have I desired of the LORD, that will I seek
      after; that I may dwell in the house of the LORD all
      the days of my life, to behold the beauty of the LORD,
      and to inquire in his temple."            
                               Psalms 27:4       




More information about the Python-list mailing list