On 3/27/22 18:57, Kirill Ratkin wrote: > Hi > > You can get all methods of your object and check the method you want to call > is > there or not. > > |methods = [method for method in dir(<your_object>) if > callable(getattr(<your_object>, method))] if 'method_you_need' in methods: > <your_object>.<method_you_need> // BR | >
I don't understand how this may help. Assume somebody has a codebase of 15T lines of Python code. How do you want to apply your method? But perhaps I overlook things. -- Manfred > 27.03.2022 12:24, Manfred Lotz пишет: >> Let's say I have a Python app and have used an undefined method somewhere. >> Let >> us further assume I have not detected it thru my tests. >> >> Is there a way to detect it before deploying the app? pylint doesn't notice >> it. >> >> >> Minimal example: >> >> #!/usr/bin/env python3 >> >> import logging >> from logging import Logger >> from random import randrange >> >> def main(): >> """ >> Below logger.err gives >> >> 'Logger' object has no attribute 'err' >> """ >> >> logger = logging.getLogger('sample') >> logger.setLevel(logging.DEBUG) >> handler = logging.StreamHandler() >> logger.addHandler(handler) >> >> num = randrange(0,1000) >> if num == 0: >> logger.err("got zero") >> else: >> logger.info(f'got a positive integer: {num}') >> >> if __name__ == "__main__": >> main() >> >> >> -- https://mail.python.org/mailman/listinfo/python-list