a beginner, beginners question

klaus kla at us.de
Wed Mar 19 11:40:10 CET 2008


Hello,

I'm trying to learn python programming and so far so good. However when 
trying to master the oop side I ran into a small problem.

I think I've done everything ok as outlined below. But I just don't 
understand why the `method' of `class' example isn't printing any of the 
variables that I have set earlier on ? Could someone please explain to me 
what it is I am doing wrong ? 

Thank you so much !

#!/usr/bin/env python

class example:
    def __init__(self, foo, bar):
        self.foo = foo
        self.bar = bar

    def method(self):
        print "method ... :" 
        print self.foo
        print self.bar


if __name__ == "__main__":
    obj = example 
    obj.foo = "var1"
    obj.bar = "var2"
    obj.method



More information about the Python-list mailing list