title: How to leave member function undetermined until creation of an object in Python?
body: <p>I have a class <code>Node</code> which should contain an activation function. But what activation function it will be must be determined at the moment of creation of an object using <code>kwargs</code>. Like so,</p>
  
  <pre><code>n1 = Node(activation='name_of_activation function')
  </code></pre>
  
  <p>I have working example, but I do not know if I missing something. This is my code:</p>
  
  <pre><code>import math
  
  
  def Signum(x):
      return 1 if x &gt; 0 else 0 
  
  def Sigmoid(x):
      return math.tanh(x) 
  
  def Sin(x):
      return math.sin(x)
  
  
  class Node():
      '''  
      This is class of one node
  
      Each node contains an activation function.
      '''  
      def __init__(self, **kwargs):
          #possible functions
          self.__functions = { 'sgn' : Signum, 'sigmoid' : Sigmoid, 'sin' : Sin }
          self.__activate = self.__functions[kwargs.get('activation', Sigmoid)]                                       
  
       def Activation(self, input_value):
           return self.__activate(input_value)
  
  n1 = Node(activation='sgn')
  n2 = Node(activation='sigmoid')
  n3 = Node(activation='sin')
  print n1.Activation(-1), n2.Activation(-1), n3.Activation(-1)
  </code></pre>
  
  <p>I do not know if it is right to do what I want in this manner, i.e. it happens that I have two references to one function: <code>self.__activate</code> and <code>Activation</code>. But I do not know how to get rid of it because:</p>
  
  <ol>
  <li>On the one hand, I want to use key-value principle for declaration an object.</li>
  <li>On the other hand, it needs to be possible to call method outside of class.</li>
  </ol>
  
  <p><strong>Question</strong>: How to leave the activation function undetermined until moment of declaration of an object at which it determined by kwarg? Also, it needs to be possible to call the activation function outside class.</p>