overloading *something

James Stroud jstroud at mbi.ucla.edu
Wed Nov 9 00:38:12 EST 2005


On Monday 07 November 2005 20:36, Alex Martelli wrote:
> Ron Adam <rrr at ronadam.com> 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 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!).

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 ?
TypeError: doit() argument after ** must be a dictionary


UserDict should be isomorphic with a dict. The fact that it is not in this 
case seems terribly un-pythonic to me.

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list