Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'subject:Python': 0.05; 'objects,': 0.07; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'immutable': 0.09; 'message-id:@stoneleaf.us': 0.09; 'specified,': 0.09; 'tuple': 0.09; 'typeerror:': 0.09; 'example:': 0.11; '__slots__': 0.16; 'hint:': 0.16; 'object()': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'basically': 0.18; 'python?': 0.18; '>>>': 0.20; '"",': 0.22; 'header:In-Reply-To:1': 0.24; '(most': 0.24; 'properties': 0.24; 'header:User-Agent:1': 0.26; 'not.': 0.27; 'consequence': 0.29; 'subject:other': 0.29; '~ethan~': 0.29; 'gets': 0.32; 'subject:all': 0.32; 'class': 0.33; 'instances': 0.33; 'null': 0.33; 'traceback': 0.33; 'file': 0.34; 'that,': 0.34; 'to:addr:python-list': 0.35; 'fresh': 0.35; 'instance': 0.35; 'received:10': 0.37; 'subject:: ': 0.37; 'pm,': 0.39; 'does': 0.39; 'to:addr:python.org': 0.39; 'where': 0.40; 'why': 0.40; 'different': 0.64; 'decided': 0.65; 'subject:have': 0.80; "'object'": 0.84; 'object:': 0.84; 'psuedo-code': 0.84; 'received:10.1.10': 0.84; 'subject:you': 0.88 Date: Fri, 22 May 2015 14:15:22 -0700 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Ah Python, you have spoiled me for all other languages References: <555f440a$0$12990$c3e8da3$5496439d@news.astraweb.com> <201505221914.t4MJE3e9009120@fido.openend.se> <555F84CD.9010204@mrabarnett.plus.com> <87k2w0mjvc.fsf@elektro.pacujo.net> In-Reply-To: <87k2w0mjvc.fsf@elektro.pacujo.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ 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: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1432329332 news.xs4all.nl 2944 [2001:888:2000:d::a6]:37104 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:91075 On 05/22/2015 01:34 PM, Marko Rauhamaa wrote: > Ian Kelly : > >> An "object" in Javascript is basically just a collection of >> properties. For example: >> >> js> typeof([1, 2, 3]) >> "object" >> js> typeof({a: 1, b: 2, c: 3}) >> "object" >> >> Here's what happens when you try to access a property on null: >> >> js> null.foo >> typein:18:0 TypeError: null has no properties > > That's not all that different from Python, where object() returns a > fresh instance at each invocation. However: > > >>> object().x = 3 > Traceback (most recent call last): > File "", line 1, in > AttributeError: 'object' object has no attribute 'x' > > Why are object instances immutable in Python? # psuedo-code class object: __slots__ = () class bad_object: "__slots__ not specified, so automatically gets a __dict__" class tuple(...) <- object or bad_object? hint: the clue is in the name ;) __slots__ = () If tuple is based on bad_object, it will get a __dict__ and be very-mutable. In order to have slightly-mutable or immutable objects, the base class has to not have a __dict__, so object does not. Mind you, I don't know if that's the reason why it was decided to be like that, or just a nice consequence of the choice to do it that way. -- ~Ethan~