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)
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
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
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?
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
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
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 ?
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
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
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
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
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.
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):
...
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
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!).
15 matches
Mail list logo