Re: overloading *something
- From: Robert Kern <robert.kern@xxxxxxxxx>
- Date: Mon, 07 Nov 2005 20:21:58 -0800
James Stroud wrote:
> Hello All,
>
> How does one make an arbitrary class (e.g. class myclass(object)) behave like
> a list in method calls with the "*something" operator? What I mean is:
>
> myobj = myclass()
>
> doit(*myobj)
>
> I've looked at getitem, getslice, and iter. What is it if not one of these?
>
> And, how about the "**something" operator?
Avoiding magic at the expense of terseness, I would do something like
the following:
class myclass(object):
def totuple(self):
...
def todict(self):
...
myargs = myclass()
mykwds = myclass()
doit(*myargs.totuple(), **mykwds.todict())
--
Robert Kern
rkern@xxxxxxxx
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
.
- Prev by Date: BayPIGgies: November 10, 7:30pm (Google)
- Next by Date: Re: gmpy 1.01 rc near... anybody wanna test>
- Previous by thread: Re: overloading *something
- Next by thread: Re: overloading *something
- Index(es):
Relevant Pages
|