Hi all,
Suppose you have this class:
class foo:
def bar():
Suppose you also have the strings "foo" and "bar". How can you obtain the
function foo.bar()?
Why don't you type these things into an interactive python session
and see what happens? Also, foo.bar will be an unbound method of foo,
not a function per se. You could experiment a little, e.g.,
... def bar():
...
File "<stdin>", line 3
^
IndentationError: expected an indented block ... def bar(): return 'bar is the name' # you could have done this
... Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unbound method bar() must be called with foo instance as first argument (got nothing
instead) Traceback (most recent call last):
... def bar(self): return self, 'bar is the name' # you could have done this
... Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: unbound method bar() must be called with foo instance as first argument (got int inst
ance instead) (<__main__.foo instance at 0x02EF756C>, 'bar is the name')
Someone can explain. If you do some of your own work, it will help even the load.
Have you looked at any documentation? Start at
http://www.python.org/
and click a few things. There seems to be a beginners guide link under documentation
in the sidebar to the left ;-)
Regards,
Bengt Richter