Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '(especially': 0.07; '[0,': 0.09; 'builtin': 0.09; 'try:': 0.09; 'subject:question': 0.10; 'cc:addr:python-list': 0.11; 'jan': 0.12; '20]': 0.16; 'builtins': 0.16; 'cc:name:python list': 0.16; 'email addr:udel.edu>': 0.16; 'email name:<tjreedy': 0.16; 'extraneous': 0.16; 'reedy': 0.16; 'subject:class': 0.16; 'typeerror:': 0.16; 'wrote:': 0.18; '<': 0.19; 'replacing': 0.19; '>>>': 0.22; 'input': 0.22; 'memory': 0.22; 'hack': 0.22; 'cc:addr:python.org': 0.22; '\xa0if': 0.24; 'mon,': 0.24; 'cc:2**0': 0.24; '>': 0.26; 'header:In-Reply-To:1': 0.27; 'correct': 0.29; 'chris': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; '>>>>': 0.31; 'python).': 0.31; 'another': 0.32; 'beginning': 0.33; 'except': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'add': 0.35; 'there': 0.35; 'doubt': 0.36; 'subject:regarding': 0.36; 'done': 0.36; 'similar': 0.36; 'starting': 0.37; 'pm,': 0.38; 'does': 0.39; '8bit%:6': 0.40; 'dave': 0.60; 'took': 0.61; 'range': 0.61; "you're": 0.61; 'first': 0.61; 'times': 0.62; 'hours': 0.66; 'yes': 0.68; 'find.': 0.84; 'angel': 0.91; 'edwards': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=iyYTuWu2qnT+fOsU/oOz4Ig1s6WNkZjA6aDRrBbV55A=; b=v52fy8vhOSNTBBT0NLokWSvrB073ip3gtS2HhR1HPmxv6QN5C2TjCI8+aPmR78uqDM paOkXntPTeeWKLT5NA+4yeBpZBkAxmoKakUmEj5t79HEHzHXCgydC3M0d59bI70fZ1gl EQsXADVQ2phtvg4g5FSTwYI0xfkk2Ar8yLmx7YEJfWW9vuchsNnY8lz3QbofdpNCz/3k JPe4VdPNEcdekpTxxY6mqGSN0yJsbugUpjWdyQSHJOOI8GAUWWoMjTua9z4vS6Eu/uvi b6m2ZrPVX1sCIyhNl0f9wG6zWvpcfbElLtmkE+dwHG3TD+oNx399r20TRZx9Pvu8kAlR +5dA== MIME-Version: 1.0 X-Received: by 10.50.1.70 with SMTP id 6mr7053igk.54.1370922552798; Mon, 10 Jun 2013 20:49:12 -0700 (PDT) In-Reply-To: <51B6609A.4050506@davea.name> References: <51B6609A.4050506@davea.name> Date: Mon, 10 Jun 2013 23:49:12 -0400 Subject: Re: Newbie: question regarding references and class relationships From: Jason Swails To: Dave Angel Content-Type: multipart/alternative; boundary=047d7bd6c730c642d904ded8c735 Cc: python list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 136 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1370922555 news.xs4all.nl 15977 [2001:888:2000:d::a6]:49294 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:47636 --047d7bd6c730c642d904ded8c735 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Jun 10, 2013 at 7:26 PM, Dave Angel wrote: > On 06/10/2013 06:54 PM, Chris Angelico wrote: > >> On Tue, Jun 11, 2013 at 8:39 AM, Grant Edwards >> wrote: >> >>> On 2013-06-10, Terry Jan Reedy 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 --047d7bd6c730c642d904ded8c735 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

<= /div>


On Mon, = Jun 10, 2013 at 7:26 PM, Dave Angel <davea@davea.name> wrote:=
On 06/10/2013 06:54 PM, Ch= ris Angelico wrote:
On Tue, Jun 11, 2013 at 8:39 AM, Grant Edwards <invalid@invalid.invalid&= gt; wrote:
On 2013-06-10, Terry Jan Reedy <tjreedy@udel.edu> wrote:

Another principle similar to 'Don't add extraneous code' is = 9;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<= br> a database ID.

ChrisA


And times where you're deliberately replacing a built-in

try:
=A0 =A0input =3D raw_input
except ....

Yes but this is a hack to coerce Python2/3 compatibilit= y. =A0You're no doubt correct that it's intentional rebinding with = a definite aim, but if the PyArchitects had their way, this would be unnece= ssary (and discouraged) as well.

The first time I remember re= binding a builtin was completely accidental (and at the very beginning of m= e learning and using Python).

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

# bunches of code

for i in range(len(data)):
=A0 =A0if data[i] > range[0] and data[i] < range[1]:
=A0 =A0 =A0 do_so= mething

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


That one = drove me nuts. Took me hours to find. =A0I still avoid rebinding builtins j= ust from the memory of the experience :)

--Jason
--047d7bd6c730c642d904ded8c735--