title: Constants Local to Member Functions
body: <p>I am looking for a good solution for where to put (semantic) constants inside a class that are only relevant to some specific member function. I don't want to initialize these constants every time I call the member function, but I also do not want to clog up the class with them:</p>
  
  <pre><code>class C:
      def __init__(self):
          # possible class related constants here
          self.func_constant = some_value # meh, does not belong here
  
      def func(self):
          func_constant = some_value # ... no, that is inefficient
  </code></pre>
  
  <p>If this was in the context of free functions, I would use a closure:</p>
  
  <pre><code>def make_func():
      constant = some_value
      def func():
          #code
      return func
  
  func = make_func()
  </code></pre>
  
  <p>I don't know of a way to declare member functions as the return value of a closure though. I mean I could do this:</p>
  
  <pre><code>class C:
      def __init__(self):
          # possible class related constants here
          self.func = make_func()
  </code></pre>
  
  <p>But that is bad design for a whole different set of reasons, and might not even work, if <code>func</code> needs to access other members of <code>C</code>.</p>
  
  <p>Therefore, my question: Is there a way to have member function local constants, that are only initialized once, rather than every function call.</p>