0

I want to call an undefined method, but it is defined in Pyro Daemon. For example, we have the class Sender without method publish, and I used __getattr__ for call undefined method.

For example:

class Sender:
    ...
        def __getattr__(self, name):
            def method(*args):
                """
                for example name = publish and I want to call method self.proxy.publish
                """
                self.call_if_connected(lambda: self.proxy.name(args))
            return method

Sender.publish()

What do I need to do?

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Vooply
  • 1
  • 1
  • Does this answer your question? [\_\_getattr\_\_ for static/class variables in python](https://stackoverflow.com/questions/3155436/getattr-for-static-class-variables-in-python) – enzo Jul 30 '21 at 17:54
  • Not really ( when I got name, I want to call the method which this name if name = publish, I want to call method publish, not name – Vooply Aug 01 '21 at 15:50

1 Answers1

0

I found answer

result = eval("self.proxy." + name + "(args)")

so when I called undefined method, that goes to getattr and after call right method

Vooply
  • 1
  • 1