Re: overloading *something

2005-11-09 Thread Robert Kern
James Stroud wrote: > That **kwargs insists on using the C-side interface is precisely the > annoyance > to which I am referring. I should be able to write a dictionary-like > interface in python and **kwargs should in turn be able to use it. If the > retort is that the C-side interface is use

Re: overloading *something

2005-11-09 Thread [EMAIL PROTECTED]
Robert Kern wrote: > James Stroud wrote: > > > Does anyone else find the following annoying: > > > > py> from UserDict import UserDict > > py> aud = UserDict({"a":1, "b":2}) > > py> def doit(**kwargs): > > ... print kwargs > > UserDict only exists for backwards compatibility with old code that us

Re: overloading *something

2005-11-09 Thread James Stroud
On Tuesday 08 November 2005 22:54, Robert Kern wrote: > James Stroud wrote: > > Does anyone else find the following annoying: > > > > py> from UserDict import UserDict > > py> aud = UserDict({"a":1, "b":2}) > > py> def doit(**kwargs): > > ... print kwargs > > ... > > py> aud > > {'a': 1, 'b': 2}

Re: overloading *something

2005-11-08 Thread Robert Kern
James Stroud wrote: > Does anyone else find the following annoying: > > py> from UserDict import UserDict > py> aud = UserDict({"a":1, "b":2}) > py> def doit(**kwargs): > ... print kwargs > ... > py> aud > {'a': 1, 'b': 2} > py> doit(**aud) > Traceback (most recent call last): > File "", line

Re: overloading *something

2005-11-08 Thread James Stroud
On Monday 07 November 2005 20:36, Alex Martelli wrote: > Ron Adam <[EMAIL PROTECTED]> wrote: > > 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 m

Re: overloading *something

2005-11-08 Thread Peter Otten
James Stroud wrote: > I was attempting to re-define iter of a subclassed list, to find the > "magic" method, but it didn't work. >>> class List(list): ... def __iter__(self): return iter("abc") ... >>> a = List([1,2,3]) >>> list(a) ['a', 'b', 'c'] >>> tuple(a) (1, 2, 3) list-to-tuple conver

Re: overloading *something

2005-11-08 Thread Bengt Richter
On Mon, 7 Nov 2005 20:39:46 -0800, James Stroud <[EMAIL PROTECTED]> wrote: >On Monday 07 November 2005 20:21, Robert Kern wrote: >> 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 "*som

Re: overloading *something

2005-11-07 Thread Ron Adam
Alex Martelli wrote: > Ron Adam <[EMAIL PROTECTED]> wrote: > > >>James Stroud wrote: >>>And, how about the "**something" operator? >>> >>>James >> >>A dictionary would be pretty much the same except subclassed from a >>dictionary of course. > > > I believe this one is correct (but I have no

Re: overloading *something

2005-11-07 Thread James Stroud
On Monday 07 November 2005 20:36, Alex Martelli wrote: > > > I've looked at getitem, getslice, and iter. What is it if not one of > > > these? > > Obviously James hadn't looked at __iter__ in the RIGHT way! I was attempting to re-define iter of a subclassed list, to find the "magic" method, but i

Re: overloading *something

2005-11-07 Thread Leif K-Brooks
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) Make it iterable: >>> class Foo(object): ... def __iter__(se

Re: overloading *something

2005-11-07 Thread Alex Martelli
Ron Adam <[EMAIL PROTECTED]> wrote: > 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

Re: overloading *something

2005-11-07 Thread James Stroud
On Monday 07 November 2005 20:21, Robert Kern wrote: > 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(*myob

Re: overloading *something

2005-11-07 Thread Ron Adam
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__

Re: overloading *something

2005-11-07 Thread Robert Kern
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 o