[PyKDE] Python/PyKDE newbie question

Albert Wagner alwagner at tcac.net
Tue Feb 1 14:02:04 GMT 2000

Hi, Boudewijn.  I'm working my way through it.
> f(**args) means that within function f you have access to a
> _dictionary_ of arguments: try:
> def f(**args):
>   for key, value in args:
>           print key, value
> f(a="aaa", b="bbb", c="ccc")

I couldn't make this work. I changed the last line and got this:

>>> def f(**args):
...     for key, value in args:
...             print key, value
>>> f({1:"aaa", 2:"bbb", 3:"ccc"})
Traceback (innermost last):
  File "<stdin>", line 1, in ?
TypeError: too many arguments; expected 0, got 1  

> class MyListViewItem(QListViewItem):
> <snip>
>   def __init__(self, *args):
>     apply(QListViewItem.__init__,(self,)+args)
>                 self.setPixMap(Icon("mini/folder_open.xpm"))
> With this construction, you can create instances from MyListViewItem
> like:
>   item=MyListViewItem(parent, "aaa")
> or
>   item=MyListViewItem(parent, sibling, "aaa", "bbb")
I think I understand this. In the first instance __init__ receives: 
self, parent, "aaa" 
and in the second instance __init__ receives:
self, parent, "aaa", "bbb".  Is that correct?  
Now,  what are "parent" and "sibling"?  I am guessing that if the call
to the class MyListViewItem is from a container class that the call
would look something like this:
	item=MyListViewItem(self, "aaa")
in which case __init__ receives:
	self, parent, "aaa"
where "parent" of the MyListViewItem instance is the container class. 
Is this correct?

I thank you very much for your explanation.  That took a considerable
amount of time; almost a mini-tutorial.

"Mutual cooperation can emerge in a world of egoists without central
control, by starting with a cluster of individuals who rely on
reciprocity"   --Robert Axelrod

More information about the PyQt mailing list