another easy (im sure) newbie question

Oleg Broytmann phd at phd.russ.ru
Wed Mar 1 09:26:54 EST 2000


On Wed, 1 Mar 2000, Shaun Hogan wrote:
> ok i started learning python a week ago.

   Welcome!

> ive followed Guido's tutorial and another one, i have a good grasp of everthing up to Classes, now the example in the tutorial 9.3.2:
> 
>                         class MyClass:
>                                  "A simple example class"
>                                  i = 12345
>                                  def f(x):
>                                      return 'hello world'
> is where i am at.
> the tutorial says "MyClass.i and MyClass.f are valid attribute references, returning an integer and a function object,"
> MyClass.i returns "12345" fine...but MyClass.f gives me "<unbound method MyClass.f>"
> how do i get it to return "hello world" or whatever its supposed to do?

   First, you must create an instance of the class:

this = MyClass()

   And then call the instance's method:

this.f()

Oleg.
---- 
    Oleg Broytmann      Foundation for Effective Policies      phd at phd.russ.ru
           Programmers don't die, they just GOSUB without RETURN.





More information about the Python-list mailing list