Modifying built-in function
<p>Let's consider any user-defined pythonic class. If I call <code>dir(obect_of_class)</code>, I get the list of its attributes:</p>

<pre><code>['__class__', '__delattr__', '__dict__', '__dir__', ... '__weakref__', 'bases', 
'build_full_name', 'candidates', ... 'update_name'].
</code></pre>

<p>You can see 2 types of attributes in this list:</p>

<ul>
<li>built-in attributes, </li>
<li>user defined.</li>
</ul>

<p>I need to override <code>__dir__</code> so, that it will return only user defined attribltes. How I can do that? </p>

<p>It is clear, that if in overridden function I call itself, it gives me infinite recursion. So, I want to do somethig like this:</p>

<pre><code>def __dir__(self):
        return list(filter(lambda x: not re.match('__\S*__', x), dir(self)))
</code></pre>

<p>but evade the infinite recursion.</p>

<p>In general, how can I modify a built-in function if I don't want to write it from scratch but want to modify the existing function?</p>