<div dir="ltr"><div class="gmail_default" style="color:#000000"><br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 10, 2013 at 7:26 PM, Dave Angel <span dir="ltr"><<a href="mailto:davea@davea.name" target="_blank">davea@davea.name</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">On 06/10/2013 06:54 PM, Chris Angelico wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On Tue, Jun 11, 2013 at 8:39 AM, Grant Edwards <invalid@invalid.invalid> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 2013-06-10, Terry Jan Reedy <<a href="mailto:tjreedy@udel.edu" target="_blank">tjreedy@udel.edu</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Another principle similar to 'Don't add extraneous code' is 'Don't<br>
rebind builtins'.<br>
</blockquote>
<br>
OK, we've all done it by accident (especially when starting out), but<br>
are there people that rebind builtins intentionally?<br>
</blockquote>
<br>
There are times when you don't care what you shadow, like using id for<br>
a database ID.<br>
<br>
ChrisA<br>
<br>
</blockquote>
<br></div>
And times where you're deliberately replacing a built-in<br>
<br>
try:<br>
   input = raw_input<br>
except ....</blockquote><div><br></div><div style="color:rgb(0,0,0)" class="gmail_default">Yes but this is a hack to coerce Python2/3 compatibility.  You're no doubt correct that it's intentional rebinding with a definite aim, but if the PyArchitects had their way, this would be unnecessary (and discouraged) as well.</div>
<div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default">The first time I remember rebinding a builtin was completely accidental (and at the very beginning of me learning and using Python).</div>
<div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default"># beginner's crappy code</div><div style="color:rgb(0,0,0)" class="gmail_default">range = [0, 20]</div>
<div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default"># bunches of code</div><div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default">
for i in range(len(data)):</div><div style="color:rgb(0,0,0)" class="gmail_default">   if data[i] > range[0] and data[i] < range[1]:</div><div style="color:rgb(0,0,0)" class="gmail_default">      do_something</div><div style="color:rgb(0,0,0)" class="gmail_default">
<br></div><div style="color:rgb(0,0,0)" class="gmail_default">TypeError: 'list' object is not callable... # what the heck does this mean??</div><div style="color:rgb(0,0,0)" class="gmail_default"><br></div><div style="color:rgb(0,0,0)" class="gmail_default">
<br></div><div style="color:rgb(0,0,0)" class="gmail_default">That one drove me nuts. Took me hours to find.  I still avoid rebinding builtins just from the memory of the experience :)</div><div style="color:rgb(0,0,0)" class="gmail_default">
<br></div><div style="color:rgb(0,0,0)" class="gmail_default">--Jason</div></div></div></div>