Definition of 'apply' of MDI GUI
Gerrit Holl
gerrit at nl.linux.org
Wed May 28 08:47:44 EDT 2003
anson schreef op woensdag 28 mei om 14:27:58 +0000:
> Dear people,
>
> I don't understand EXACTLY how apply works in MDI GUIS? What's the purpose of it?
>
> apply(QWidget.__init__,(self, parent) + args)
The purpose of apply was, before Python 2.3, to be able to call
functions or methods with lists 'applied' as arguments. For
example:
1 >>> def foo(*args): return args
1 ...
2 >>> l = ['a', 1, {"yeah!": True}]
3 >>> foo(l)
(['a', 1, {'yeah!': True}],)
But that is not what we want.
We want something that equals:
foo(['a', 1, {"yeah!": True}])
4 >>> apply(foo, l)
('a', 1, {'yeah!': True})
That's more like it.
As of Python 2.3, you can do:
5 >>> foo(*l)
('a', 1, {'yeah!': True})
apply is redundant now.
The statement above equals:
Qwidget.__init__(self, parent, *args)
...so that all elements of args are passed seperately, and not as one tuple.
See also:
http://www.python.org/dev/doc/devel/lib/built-in-funcs.html#l2h-4
Hope this helps!
yours,
Gerrit.
--
196. If a man put out the eye of another man, his eye shall be put out.
-- Hammurabi, Code of Law
--
Asperger Syndroom - een persoonlijke benadering:
http://people.nl.linux.org/~gerrit/
Het zijn tijden om je zelf met politiek te bemoeien:
http://www.sp.nl/
More information about the Python-list
mailing list