[Tutor] Inheritance and *args

Joseph J. Strout joe@strout.net
Mon, 26 Jul 1999 10:24:13 -0700


--============_-1279112630==_ma============
Content-Type: text/plain; charset="us-ascii"

At 9:16 AM -0700 07/26/99, Art Siegel wrote:

>    self.y=args[1]
>IndexError: tuple index out of range
>Apparently because the arguments to Point(1,2,3) is read in as a single
>element tuple, whose single element is the 3 element tuple (1,2,3).

Yep.

>Whereas Position(1,2,3) is processed as a three element tuple, with
>elements 1,2,3.

Yep again.

>Is there a straightforward approach to accomplish above inheritance??

Yep^3.  Well, reasonably straightforward -- slightly complicated by having
an additional parameter ('self'):

	apply(Position.__init__, (self,) + args)

In cases where you have a list or tuple of arguments, but you need to pass
them to a function as separate arguments rather than a single object, you
use 'apply'.

Cheers,
-- Joe
,------------------------------------------------------------------.
|    Joseph J. Strout           Biocomputing -- The Salk Institute |
|    joe@strout.net             http://www.strout.net              |
`------------------------------------------------------------------'
--============_-1279112630==_ma============
Content-Type: text/enriched; charset="us-ascii"

At 9:16 AM -0700 07/26/99, Art Siegel wrote:


<excerpt>    self.y=args[1]

IndexError: tuple index out of range

Apparently because the arguments to Point(1,2,3) is read in as a single
element tuple, whose single element is the 3 element tuple (1,2,3).

</excerpt>

Yep.


<excerpt>Whereas Position(1,2,3) is processed as a three element tuple,
with elements 1,2,3.

</excerpt>

Yep again.


<excerpt>Is there a straightforward approach to accomplish above
inheritance??

</excerpt>

Yep^3.  Well, reasonably straightforward -- slightly complicated by
having an additional parameter ('self'):


	apply(Position.__init__, (self,) + args)


In cases where you have a list or tuple of arguments, but you need to
pass them to a function as separate arguments rather than a single
object, you use 'apply'.


Cheers,

-- Joe 

,------------------------------------------------------------------.

|    Joseph J. Strout           Biocomputing -- The Salk Institute |

|    joe@strout.net             http://www.strout.net              |

`------------------------------------------------------------------'

--============_-1279112630==_ma============--