
(only referring to the second use case here) On 30.10.2014 09:07, Antony Lee wrote:
[snip] - In Qt programs (although I assume similar ideas apply to other GUI toolkits), where functions that operate on the GUI can only be called from the main thread, but "signals" (in the Qt sense of the term) can be used to communicate between threads, I find it useful to define a "call this in the GUI thread" generic signal. The implementation is essentially
class Main(QMainWindow): any_callable_signal = pyqtSignal(object) def __init__(self, *args, **kwargs): <...> self.any_callable_signal.connect(lambda f: f()) # <- operator.call seems to express this better. def call_in_gui_thread(self, func): self.any_callable_signal.emit(func)
How is that different from directly passing f? Or use functools.partial in case you need to pass additional, fixed arguments to f. regards, jwi
Antony
2014-10-29 17:57 GMT-07:00 Steven D'Aprano <steve@pearwood.info>:
A simple suggestion: add "operator.call" and "operator.__call__", which would provide a function like Python2's "apply" (but it'd be called with already unpacked arguments, i.e. operator.call(f, *args, **kwargs)). Why? To be able to pass it as an argument to other function, just like
On Wed, Oct 29, 2014 at 03:39:59PM -0700, Antony Lee wrote: the
other functions defined in the "operator" module.
I think you want something like this?
def call(callable, *args, **kwargs): return callable(*args, **kwargs)
Can you give an example of how you might use this call method? It doesn't have to be a real world use-case, just an illustration.
Perhaps I'm being a bit dim-witted today, but I'm having trouble thinking of where I would use this operator.call rather than just directly applying *args, **kwargs to the callable.
-- Steven _______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/