简体   繁体   中英

How do i call this method for debugging?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM