Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: can't add variables to instances of built-in classes Date: Sun, 17 Jul 2016 22:02:31 +1000 Lines: 14 Message-ID: References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de ed1V+4Syvr7UuXqenLOSEwCkkleRArCXYk7pLVnuxH8w== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'memory.': 0.05; 'attributes': 0.07; 'stops': 0.07; 'cc:addr:python-list': 0.09; 'instances.': 0.09; 'stored': 0.10; 'python': 0.10; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'only?': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'wrote:': 0.16; 'memory': 0.17; 'instance,': 0.18; 'variable': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'leave': 0.23; 'header:In-Reply-To:1': 0.24; 'feature': 0.24; 'message- id:@mail.gmail.com': 0.27; 'program,': 0.29; "i'm": 0.30; 'that.': 0.30; 'class': 0.33; '(for': 0.34; 'received:google.com': 0.35; "isn't": 0.35; 'there': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'doing': 0.38; 'names': 0.38; 'why': 0.39; 'test': 0.39; 'sure': 0.39; 'enough': 0.39; 'subject:-': 0.39; 'rather': 0.39; 'your': 0.60; 'relatively': 0.63; 'worth': 0.67; 'saving': 0.70; 'jul': 0.72; 'chrisa': 0.84; 'strings)': 0.84; 'to:none': 0.91; 'subject:add': 0.91; 'wilson': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:cc; bh=7PWY9HR8EBTMwRxkBR4NNzbqPglykbFMMADbm4cWckk=; b=YvWx+LBGd2wRYLGG5JtMhnTJOezhz7C7SXDU2Lb8TKFu4BXModeUVS10LYlYW52eaL wytYNMDcvKPZvqJ9quNfskx34opb5uwifmEjn4C9r9HzD5ns09ACBik11rjo+8eR62BH 7P49/nGXlP54WHrPrcV46yEWu0koIxYyFiJwHBI2eIkTP02oXltaiShJLxptWZRcCFVs Rnexi1DEmtB2oY4xvQVcPaX/EqScVXzmfNRdAwFGMXH2dKq+3KX3IUFOQgNNxTzkh5QD MZlH7NPlmyR9d32Qg9Dyowq4wOQxZx0W1wonA2duj22iFouiAUpAq7T/NOFBR3VbOod/ nh7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:cc; bh=7PWY9HR8EBTMwRxkBR4NNzbqPglykbFMMADbm4cWckk=; b=Sw8hu5Jh9zdIMy1nYvS/p2qXnbuBEpUFPppoRJ8LMtJquISIzVPOJiB0SaXNv69AMx qtcYVG9/oZwxu8Xy/hrRDA6iH8J/OsYxMrzeWIu6oE1vrHgTGUZVa7Ea0N21SHbj2tQZ Xkyo5lBxzRjtrxKiKMO8rwpU6WfGqqDzhurX3jheVNnB1f6AEeip2POoAbIrMnT1iMGE nUEjnFt8jTLPOO+1ZDMCW16pgBNt2GbJ21fnJR8xpQALdBdP+S+HedGV2t7OBRSDPwvu NBVofgGmieLCAC4oGWyBZyBGoHu+L4Cp9cHk6FRNdpJeBg1K2eOunzYgu0p28GECdMMN 0r1g== X-Gm-Message-State: ALyK8tJod7CqhaZDgFjOBfsHK+T5UVCvHy9rgrGL+8jnKHKWadgreyoK2h3ebZa1w1HpFMoMy9uridH6iMYSbg== X-Received: by 10.28.1.23 with SMTP id 23mr31828481wmb.22.1468756951807; Sun, 17 Jul 2016 05:02:31 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <4f796d95-0e87-4610-a0a8-1eff07c60ace@googlegroups.com> Xref: csiph.com comp.lang.python:111574 On Sun, Jul 17, 2016 at 9:50 PM, Wilson Ong wrote: >> Use this feature sparingly, only when you know that there are going to be >> many (millions rather than thousands) of Test instances. > > Why use it sparingly? Is it for extensibility? What if I'm pretty sure that my class is going to have exactly these attributes only? "Pretty sure" isn't enough justification for a relatively meagre saving of memory. Much easier to leave it flexible. It's only once the memory saving stops being "relatively meagre" (for instance, with the built-in 'str' type - there are a LOT of strings in a Python program, since your variable names are stored as strings) that it's worth doing that. ChrisA