title: How to override getattr or getattribute in python to call gettattr or getattribute inside itself as in lazy recursive directory listing
body: <p>For example something like this:</p>
  <pre class="lang-py prettyprint-override"><code>class DotTabLoader():
      def __init__(self, basedir, loaderfun):
          self._basedir = pathlib.PosixPath(basedir)
          self._loaderfun = loaderfun
          self._list = list(self._basedir.glob('*/'))
          self._names = [x.name.split('=')[1] for x in self._list]
          self._names_dict = dict(zip(self._names, range(self._names)))
      def __dir__(self):
          return self._names
      def __getattribute__(self, name):
          # how to access self._list etc here?
          return super().__getattribute__(name)
      
  </code></pre>
  <p>You get errors with infinite recursion.</p>
  <p><strong>UPDATE:</strong></p>
  <p>Correct way is this:</p>
  <pre class="lang-py prettyprint-override"><code>class DotTabLoader():
      def __init__(self, basedir, loaderfun):
          self._basedir = pathlib.PosixPath(basedir)
          self._loaderfun = loaderfun
          self._list = list(self._basedir.glob('*/'))
          self._names = [x.name.split('=')[1] for x in self._list]
          self._names_dict = dict(zip(self._names, range(len(self._names))))
      def __dir__(self):
          return self._names + super().__dir__()
      def __getattr__(self, name):
          try:
              ind = self._names_dict[name]
              basedir = self._list[ind]
              return DotTabLoader(basedir, self._loaderfun)
          except KeyError as e:
              return super().__getattribute__(name)
  </code></pre>