0

So I know that it's possible to pass a function into a function. But I am using a certain library that has a member variable and a function with the same name. How do I tell python to pass the function inside of the function rather than the member variable?

The following example code shows that python will mistakingly think I am passing the member variable:

class foo():
    def __init__(self):
        self.ambiguous = "member variable" # Member variable I don't want to be passed into another function

    def ambiguous(self): # Function I want to be passed into another function
        print("function")

def testFunc(func): # This function is intended to be passed a function
    func()

def main():
    myFoo = foo()
    testFunc(myFoo.ambiguous) # this will pass the member variable (I want to pass the function)

if __name__ == "__main__":
    main()

I am using python 3.5

Kevin Tan
  • 23
  • 5
  • I believe [this](https://stackoverflow.com/questions/16140986/conflicting-variable-and-function-names-in-python) question might have some answers for you. – Ghosty Frosty Apr 20 '20 at 18:24
  • Does this answer your question? [Conflicting variable and function names in python](https://stackoverflow.com/questions/16140986/conflicting-variable-and-function-names-in-python) – Ghosty Frosty Apr 20 '20 at 18:25
  • Generally is not good practice to you use the same name for variables and functions when you coding, is misleading. Your fuctions usually do something(actions) e.g. prints, get, set, create, etc – TassosK Apr 20 '20 at 18:42
  • @GhostyFrosty I think that post tells me that variables on the left hand side can be interpreted as a function or a standard variable, but it doesn't tell me if it is possible to explicitly declare that I am passing a function, not a member variable, to another function – Kevin Tan Apr 20 '20 at 21:57
  • @TassosK I do agree it isn't good practice, but I wasn't the one who created this library :) – Kevin Tan Apr 20 '20 at 21:59

0 Answers0