title: Dispatch private class method
body: <p>I am trying to use a dispatch table to dispatch private class methods. My code looks like this:</p>
  <pre class="lang-py prettyprint-override"><code>class Snackmachine:
      __dispatch = {
          'login': __login,
          'logout': __logout,
          'addAccount': __add_user,
          'deposit': __deposit,
          'balance': __balance,
          'products': __print_products,
          'buy': __buy_product,
          'exit': __exit_program,
          'restock': __restock,
          'addProduct': __add_product
      }
  
      def __init__(self):
          ...
  
      def __login(self):
          ...
      def __logout(self):
          ...
      def __add_user(self):
          ...
      def __deposit(self):
          ...
      def __balance(self):
          ...
      def __print_products(self):
          ...
      def __buy_product(self):
          ...
      def __exit_program(self):
          ...
      def __restock(self):
          ...
      def __add_product(self):
          ...
  
      def __command_dispatch(self, command):
          '''Invokes console commands with dispatch table'''
          try:
              self.__dispatch[command]()
  
          except KeyError:
              _print_fail(&quot;## Unknown Command!&quot;)
  </code></pre>
  <p>But using this code I get the error: <code>NameError: name '_Snackmachine__login' is not defined</code></p>
  <p>I tried using</p>
  <pre class="lang-py prettyprint-override"><code>bound = self.__dispatch[command].__get__(self, type(self))
  bound()
  </code></pre>
  <p>which was suggested in another StackOverflow question, but it gave me the exact same error.</p>
  <p>I thought it has something to do with the private modifier, but when changing <em>__login()</em> to <em>login()</em> I still get a name error.</p>
  <p>So why does the name error occur and how can I fix it?</p>
  <p>Thank you in advance!</p>