[Tutor] Another Question

D-Man dsh8290@rit.edu
Tue, 16 Jan 2001 16:06:33 -0500


On Tue, Jan 16, 2001 at 05:44:10PM +0000, alan.gauld@bt.com wrote:
| > How can the method fun in class B use its option tuple to 
| > call the fun method in the class A?
| 
| I assume I'm missing the point here but this seems to do it...
| 
| >>> class A:
| ...  def fun(s,*o):
| ...    print "A fun"
         print o  # try this instead,  it's not quite right
| ...
| >>> class B(A):
| ...  def fun(s,*o):
| ...    A.fun(s,o)
| ...
| >>> b = B()
| >>> b.fun(1,2,3)
| A fun
| >>>
| 
| > The problem is caused because we can change the tuple (options).
| 
| You can create a new tuple but you can't change the original. Tuples 
| are immutable.
| 
| I think I'm missing the issue.
| 
| Alan G.

I think the "apply" response was correct.  I thought it would be as
simple as this, but then I tried it in the interpreter.  When A.fun
gets called, it has a 1-tuple as the argument "o".  Then o[0] is the
n-tuple of arguments that is desired.


-D