Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103726

Re: Dynamic object attribute creation

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Random832 <random832@fastmail.com>
Newsgroups comp.lang.python
Subject Re: Dynamic object attribute creation
Date Mon, 29 Feb 2016 11:06:04 -0500
Lines 13
Message-ID <mailman.19.1456761968.20602.python-list@python.org> (permalink)
References <56d46597$0$22756$426a74cc@news.free.fr>
Mime-Version 1.0
Content-Type text/plain
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de apnfmAYXl6uYNdisfwGXpQk6buJTGKgienDgHX8/l35A==
Return-Path <random832@fastmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'float': 0.05; '[1,': 0.09; 'ast': 0.09; 'received:internal': 0.09; 'dictionary,': 0.16; 'message-id:@webmail.messagingengine.com': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:10.202.2.44': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:compute4.internal': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'subject:object': 0.16; 'wrote:': 0.16; 'attribute': 0.18; 'int,': 0.22; 'space.': 0.22; 'feb': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; "doesn't": 0.26; 'classes': 0.30; 'class': 0.33; 'lists': 0.34; 'list': 0.34; 'but': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'received:66': 0.38; 'why': 0.39; 'to:addr:python.org': 0.40; 'save': 0.60; 'header:Message-Id:1': 0.61; 'float,': 0.84; 'not)': 0.84
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=78SmP+PR/5JuMyYDf4oaQ3o00sk=; b=P3V1ok TV6CfkkING2MkVTgrHS8FlfoSDHrQUuQisu0CMtj17ZdElri31ZXGzucPEMoKISJ OSI8WCZ4vpNRClgZohNBIRZ54+tI4dgk6YBBlRZvxujDkMIJfMeipb4AxgWByNkz 48a1mFNHZqVH84obBYWdse8ROutooVp9+T5uU=
DKIM-Signature v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=78SmP+PR/5JuMyY Df4oaQ3o00sk=; b=g2AF7CNx3CCcfg+PLrFRCnrNhJMbEc9nIOuR6VSQbYAe23G QNE3iEK1As8lSOoZo+3880sKUQsXa7N/l2GySFANMDTTS+eull6F38ICH3pCkrx+ haQvRu+eDDsPCVs8F0wohTo3H7dxaElM0I0sU9Mmt9rUQAdxwAEkrpfA5CUs=
X-Sasl-Enc AlKZIz2PXkYR92Q4J9w3P8HeZbXmqxz37EDfDnZ06d8J 1456761964
X-Mailer MessagingEngine.com Webmail Interface - ajax-aeec9b65
In-Reply-To <56d46597$0$22756$426a74cc@news.free.fr>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Xref csiph.com comp.lang.python:103726

Show key headers only | View raw


On Mon, Feb 29, 2016, at 10:36, ast wrote:
> but why doesn't it work with built-in classes int, float, list.... ?
> 
> L = [1, 8, 0]
> L.test = 'its a list !'
> 
> (however lists are mutable, int, float ... are not)

Because those classes do not have attribute dictionaries, in order to
save space.

You can make a class without an attribute dictionary, by using
__slots__.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Dynamic object attribute creation "ast" <nomail@invalid.com> - 2016-02-29 16:36 +0100
  Re: Dynamic object attribute creation Random832 <random832@fastmail.com> - 2016-02-29 11:06 -0500
  Re: Dynamic object attribute creation Ian Kelly <ian.g.kelly@gmail.com> - 2016-02-29 09:33 -0700

csiph-web