title: Atttaching an attribute to a method in Python
body: <p>I have a class:</p>
  <pre class="lang-py prettyprint-override"><code>class A:
      def foo(self):
          print(&quot;A.foo&quot;)
  </code></pre>
  <p>I want a method of the class to have an attribute so I can do something like <code>A.foo.b</code>.</p>
  <p>I tried creating a decorator which returns a callable class:</p>
  <pre><code>class AttrStorage:
      def __init__(self, b, method):
          self.b = b
          self.method = method
  
      def __call__(self, *args, **kwargs):
          return self.method(*args, **kwargs)
  
  
  def add_attr(b):
      def wrapper(method):
          return AttrStorage(b, method)
  
      return wrapper
  </code></pre>
  <p>So I could use it like this:</p>
  <pre><code>class A:
      @add_attr(1)
      def foo(self):
          print(&quot;A.foo&quot;)
  </code></pre>
  <p>Fortunately <code>A.foo.b</code> worked, but when I used the method, it gave an error:</p>
  <pre><code>&gt;&gt;&gt; A.foo.b
  1
  &gt;&gt;&gt; A().foo()
  TypeError: foo() missing 1 required positional argument: 'self'
  </code></pre>
  <p>Is this possible in python? If so, how do I do it?</p>