[Tutor] Re: Newbie OOP Question.(diff between function, module and class)

SA sarmstrong13@mac.com
Mon, 10 Jun 2002 16:36:41 -0500


On 6/10/02 12:06 PM, "Alexandre Ratti" <alex@gabuzomeu.net> wrote:

> 
> Here is a small test to try and make it more concrete:
> 
> ##
> globalFoo = "I am a global variable."
> 
> class Test:
>    classFoo = "I am a class variable."
> 
>    def __init__(self):
>        self.instanceFoo = "I am an instance variable."
>        localFoo = "I am a local variable."
>        print globalFoo
>        print self.classFoo
>        print self.instanceFoo
>        print localFoo
> 
> if __name__ == "__main__":
>    t = Test()
> ##
> 
> 
> Cheers.
> 
> Alexandre
> 
> 
Ok. This is all beginning to make more sense now.

Just a couple of more questions:

1. How does "print self.classFoo" know to print classFoo if the classFoo
   variable is defined prior to the __init__(self) function?

2. What is the purpose of the line "if __name__ == "__main__":"? (How does
   it work and why do you use this instead of just running "t = Test"?)


Thanks again in advance. Everyone here has been very helpful.

Thanks.
SA