overloading *something
Ron Adam
rrr at ronadam.com
Mon Nov 7 23:29:28 EST 2005
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:
You need to base myclass on a list if I understand your question.
class myclass(list):
def __init__(self, *items):
# change items if needed
# initate other attributes if needed
list.__init__(self, *items)
Then the line below should work. Of course it won't do much with out
something in it. ;-)
> 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?
>
> James
A dictionary would be pretty much the same except subclassed from a
dictionary of course.
Cheers,
Ron
More information about the Python-list
mailing list