-3

I want to have a dictionary where a certain key calls a value... that value is a function and I would want that function to execute. Below is my attempt to do it but all I get is the value of where it is stored in memory.

class Testing:
    def __init__(self):
        self.method = {'Method1': self.another, 'Method2': self.there}

    def launch(self, input):
        print(self.method[input])

    @staticmethod
    def another():
        print('This print statement should pop out.')

    @staticmethod
    def there():
        print('This should not appear.')

new = Testing()
new.launch('Method1')

The result that I get from that is:

<function Testing.another at 0x01519540>

Is there a way to do this?

Teacher Mik
  • 147
  • 3
  • 9

1 Answers1

1

You are missing the actual function call: (notice the added () at the end)

def launch(self, input):
        print(self.method[input]())
Uku Loskit
  • 40,868
  • 9
  • 92
  • 93