0

Assuming that func() (no parameters) returns a list. In the following code I want self.myfunction to point to the function and not the returned list. How can I do this?

class myArrayThread(threading.Thread):
    def __init__(self,ThreadName, func):
        self.ThreadName = ThreadName
        self.myfunction = func
       # ......... more stuff after this
1
  • As Jasper says: eval.in/576365 Commented May 24, 2016 at 15:27

2 Answers 2

3

It already does what you want.

You are probably calling it the following way:

myArrayThread("some_name", func())

but it should be called

myArrayThread("some_name", func)
Sign up to request clarification or add additional context in comments.

1 Comment

This was exactly the source of my problem thank you so much.
1

Posting as an answer instead of a comment for formatting purposes...

Your code already does exactly what you want:

>>> def a():
...  return [1]
... 
>>> b=a
>>> b
<function a at 0x7f4b6aeb96a8>
>>> b()
[1]
>>> a
<function a at 0x7f4b6aeb96a8>

b "points to" the function a. You have to call it to get the return value of a (or b which is just another name for the same thing, see last line)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.