On Mon, Jun 10, 2013 at 7:26 PM, Dave Angel <da...@davea.name> wrote:

> On 06/10/2013 06:54 PM, Chris Angelico wrote:
>
>> On Tue, Jun 11, 2013 at 8:39 AM, Grant Edwards <invalid@invalid.invalid>
>> wrote:
>>
>>> On 2013-06-10, Terry Jan Reedy <tjre...@udel.edu> wrote:
>>>
>>>  Another principle similar to 'Don't add extraneous code' is 'Don't
>>>> rebind builtins'.
>>>>
>>>
>>> OK, we've all done it by accident (especially when starting out), but
>>> are there people that rebind builtins intentionally?
>>>
>>
>> There are times when you don't care what you shadow, like using id for
>> a database ID.
>>
>> ChrisA
>>
>>
> And times where you're deliberately replacing a built-in
>
> try:
>    input = raw_input
> except ....


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.

The first time I remember rebinding a builtin was completely accidental
(and at the very beginning of me learning and using Python).

# beginner's crappy code
range = [0, 20]

# bunches of code

for i in range(len(data)):
   if data[i] > range[0] and data[i] < range[1]:
      do_something

TypeError: 'list' object is not callable... # what the heck does this mean??


That one drove me nuts. Took me hours to find.  I still avoid rebinding
builtins just from the memory of the experience :)

--Jason
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to