a beginner, beginners question

klaus kla at us.de
Wed Mar 19 07:17:12 EDT 2008


On Wed, 19 Mar 2008 05:57:04 -0500, Tim Chase wrote:

>> 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
> 
> This makes "obj" a synonym for "example".  You want to instantiate your
> "example" class with
> 
>    obj = example("Some foo", "Some Bar")
> 
>>     obj.foo = "var1"
>>     obj.bar = "var2"
> 
> which then makes these two lines either unneeded or an overwriting of
> the initialization
> 
>>     obj.method
> 
> and this returns a function, not the results of the function. You need
> to call it
> 
>    obj.method()
> 
> -tkc

Ok thank you for elaborating I think I've got it.

Thnkx. !




More information about the Python-list mailing list