[Tutor] Unbound methods

Magnus Lycka magnus@thinkware.se
Wed Nov 20 17:28:03 2002


At 02:10 2002-11-21 +0200, am@fx.ro wrote:
>w=WavSet

This means that w is now a synonym for WavSet.
I think you meant to do:

w = WavSet() # Note parenthesis

>print w.open()

First of all, this is as you (now) understand just another
way of saying WavSet.open()

If you first do:

w = WavSet()

then

w.open()

is really just a shorter way of writing

WavSet.open(w)

where the instance variable 'w' ends up being called self
inside the method. Right?

Since you had forgotten the () above, you wrote the
equivalent of

WavSet.open()

and of course, that's not bound to an instance. Ok?

There's another issue. You use a print inside the method
and the don't return anything (which is the same as returning
None). Then you type "print w.open()" which means that first
you print 'Open' inside the method, and then you print the
return value. So if you add the () your program will print:

Open
None
Close
None

You should probably either change your methods to:

     def open(self):
         return 'Open'

etc, or skip the print when you call them. No big issue now,
since I imagine that the body of the methods will change though...


-- 
Magnus Lycka, Thinkware AB
Alvans vag 99, SE-907 50 UMEA, SWEDEN
phone: int+46 70 582 80 65, fax: int+46 70 612 80 65
http://www.thinkware.se/  mailto:magnus@thinkware.se