Questions tagged [callable]

A task that returns a result and may throw an exception.

The Callable interface is similar to Runnable, in that both are designed for classes whose instances are potentially executed by another thread. A Runnable, however, does not return a result and cannot throw a checked exception.

759 questions
4
votes
0 answers

How to create callable jacobian function for scipy minimize routine?

I can use scipy to perform minimization without using a callable jacobian. I would like to use the callable jacobian, but cannot figure out the correct structure of the output of such a function. I have checked online for examples; the similar…
user10121139
4
votes
2 answers

How to decorate a class method with a callable class?

I want functions in a class to store their returned values in some data structure. For this purpose I want to use a decorator: results = [] instances = [] class A: def __init__(self, data): self.data = data @decorator def…
Dmitry K.
  • 1,145
  • 1
  • 9
  • 16
4
votes
1 answer

Can't use the get mothod on my Future parameter to get result of thread with the callable interface

I am trying to build a multithreading app that can calculate prime numbers (calculations done in another class), by using the methods of the other class via threadings, I need to then pass the result to the other class in order to print the…
Idris
  • 125
  • 1
  • 7
4
votes
1 answer

Ruby: BigDecimal: a class and a method at the same time?

require bigdecimal BigDecimal.class # => Class So, BigDecimal is a class. But at the same time, BigDecimal can be invoked like a method: BigDecimal("42.0") # => 0.42e2 What is the mechanism behind it? How can I see that BigDecimal is…
Min-Soo Pipefeet
  • 2,208
  • 4
  • 12
  • 31
4
votes
1 answer

xgboost model getfscore:'str' object is not callable

feat_imp = pd.Series(xgbPara.booster().get_fscore()).sort_values(ascending=False) TypeError: 'str' object is not callable I can run it in pycharm, but when I run it in pyspark, there is a Type Error. could anyone tell me why? Thanks!
Chan
  • 41
  • 1
  • 4
4
votes
2 answers

modifying a python callable so it calls before() , actual function then after()

I am not sure if this is the best way to have before and after functions be called around a function f1(). class ba(object): def __init__(self, call, before, after): self.call = call self.before = before self.after =…
Elias Bachaalany
  • 1,180
  • 2
  • 13
  • 27
4
votes
2 answers

'int' object is not callable when calculating min

I am having a very weird and frustrating error. The problem is very simple: >>> mylist [70.71, 67.23, 60.1, 62.52, 64.14, 65.4, 68.84, 61.04, 66.95, 62.22, 63.73, 62.04, 57.12, 61.3, 65.48, 61.49, 66.94, 62.68, 60.31, 64.38, 62.84, 63.03, 67.12,…
codeKiller
  • 5,493
  • 17
  • 60
  • 115
4
votes
2 answers

Convert Runnable.run() to Callable.call() in JAVA Servlet

I have problem converting my code with the runnable interface to the callable interface in the following code. I need to change, because I need to return a Sting[][] isRs by the threads. When I just change the interface to callable and chande…
user3876178
  • 241
  • 1
  • 4
  • 11
4
votes
4 answers

How to run two classes in parallel using multithreading?

I am working on a project in which I have multiple interface and two Implementations classes which needs to implement these two interfaces. Suppose my first Interface is - public Interface interfaceA { public String abc() throws…
AKIWEB
  • 19,008
  • 67
  • 180
  • 294
4
votes
1 answer

Object is "not callable" after adding __call__ method to instance

I have the following code import numpy as np class Estimator(object): name = None def __init__(self): self.__call__ = self._call class Mean(Estimator): name = 'mean' def _call(self, data): return…
Ruggero Turra
  • 16,929
  • 16
  • 85
  • 141
4
votes
2 answers

class variable functions

Say $this->varname is equal to a string for which is_callable() returns true. To call it I'd have to do $temp = $this->varname; $temp(); or... is there another way I could call it without having to create two lines? The problem with doing just…
user2256048
4
votes
1 answer

use of callable in php

I am trying to mimic php's inbuilt usort function definition in my implementation below: class heapSort { static function hsort(array &$array, callable $cmp_function){ // logic } } class utility{ static function mycomparator(){ …
pranay
  • 444
  • 1
  • 7
  • 20
4
votes
1 answer

Serialization of local class returned from Callable

This is a brainscratcher. I know this actual code is horrible on so many levels. My question is not how to do this (I know about static initialization blocks), but why this doesn't work, for the benefit of my understanding of Java…
Paul Draper
  • 78,542
  • 46
  • 206
  • 285
4
votes
1 answer

Construct a callable object from a string representing its name in Python

Let's say I have a class like this class MyClass(AnotherClass): def __init__(self, arg1, arg2): self.arg1 = arg1 self.arg2 = arg2 def f(self): #dostuff And I have the string "my class" str = "my class" I can do…
Jorge Arévalo
  • 2,858
  • 5
  • 36
  • 44
4
votes
1 answer

Is there a way to have callable objects in Groovy?

If for example I have a class named A. Can I make an object be callable, just like Python does? For example : def myObject = new A() myObject() and that would call some object method. Can it be done?
Geo
  • 93,257
  • 117
  • 344
  • 520