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} py doit(**aud)

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 used it before one

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 used

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 *something operator?

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 conversion is optimized

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 mean is: [snip] A

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 stdin, line 1, in ?

overloading *something

2005-11-07 Thread James Stroud
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

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 one of

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

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(*myobj) I've looked

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 your question.

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__(self): ...

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 it didn't

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 not checked in-depth!).