Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #54037 > unrolled thread

Accessing class attribute

Started bychandan kumar <chandan_psr@yahoo.co.in>
First post2013-09-12 14:15 +0800
Last post2013-09-12 14:15 +0800
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Accessing class attribute chandan kumar <chandan_psr@yahoo.co.in> - 2013-09-12 14:15 +0800

#54037 — Accessing class attribute

Fromchandan kumar <chandan_psr@yahoo.co.in>
Date2013-09-12 14:15 +0800
SubjectAccessing class attribute
Message-ID<mailman.298.1378966730.5461.python-list@python.org>
Hi ,

I'm new to python ,please correct me if there is any thing wrong with the way accessing class attributes.

Please see the below code .I have inherited confid in ExpectId class, changed self.print_msg  to Hello. Now  inherited confid in TestprintmsgID class.Now  I wanted to print self.print_msg value (which is changed under ExpectId class)  as Hello under TestprintmsgID. I end up with error saying TestprintmsgID has no attribute self.print_msg.  Atleast i expect the null to be printed.



class confid():
    def __init__(self):
        self.print_msg = ""

class ExpectId(confid):    

    def __init__(self):
        self.print_msg = " Hello"

    def expectmethod(self):
        print "self.print_mesg = ",self.print_msg

class TestprintmsgID(confid):   
 
    def __init__(self):
        "Created  Instance"

    def printmsgmethod(self):
        print "printmsgmethod print_msg val = ",self.print_msg---- Here is the  Attribute error


if __name__ == '__main__':
    ins1 =ExpectId()
    ins1.expectmethod()

    ins2 = TestprintmsgID()
    ins2.printmsgmethod()

Best Regards,
Chandan

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web