Reputation: 72
I'm trying to call a method from this class. Calling for check_config() method to print the value of c. New to python and some debugging advice would be great.
Tried BirdChecker.config_check() but getting error: TypeError: unbound method check_config() must be called with BirdChecker instance as first argument (got nothing instead)
I expect to print the value of c from the method config_check
Upvotes: 0
Views: 63
Reputation: 360
Your method check_config
is an instance method, which means it needs to be called on an instance of your class BirdChecker
. Try:
bird_checker = BirdChecker(control_socket=BIRD_CONTROL_SOCKET, ignore=True)
bird_checker.config_check()
The TLDR on instance vs. static methods is that instance methods must be called on an instance of a class, whereas a static method can be called on a class itself. The rule of thumb is to use instance methods only when you need access to data specific to an instance of the class. Since you need access to the control_socket
for _send_query
it makes sense that it's an instance method! However, if BIRD_CONTROL_SOCKET
and/or ignore
will never be different from instance to instance, you may want to reconsider.
Upvotes: 1