Path: csiph.com!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!news-1.dfn.de!news.dfn.de!news.informatik.hu-berlin.de!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: Dynamic object attribute creation Date: Mon, 29 Feb 2016 09:33:48 -0700 Lines: 22 Message-ID: References: <56d46597$0$22756$426a74cc@news.free.fr> <1456761964.822300.535132330.33A18241@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de NvFTOTwOSmz7+DIm7zt/DAv97GF3gjXXgh047krEUITg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'received:209.85.223': 0.03; 'float': 0.05; '[1,': 0.09; 'ast': 0.09; 'obj': 0.09; '2016': 0.16; 'dictionary,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subclassing': 0.16; 'subject:object': 0.16; 'wrote:': 0.16; 'attribute': 0.18; '>>>': 0.20; 'int,': 0.22; 'space.': 0.22; 'pass': 0.22; 'am,': 0.23; 'feb': 0.23; 'header:In-Reply-To:1': 0.24; 'mon,': 0.24; "doesn't": 0.26; 'message-id:@mail.gmail.com': 0.27; 'dictionary': 0.29; 'classes': 0.30; 'class': 0.33; 'lists': 0.34; 'list': 0.34; 'received:google.com': 0.35; 'but': 0.36; 'received:209.85': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'why': 0.39; 'does': 0.39; 'to:addr:python.org': 0.40; 'save': 0.60; "'foo'": 0.84; 'float,': 0.84; 'not)': 0.84; 'to:name:python': 0.84 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:to; bh=PYgj6Hv8ZR8R1aWRKgoyLu22euh1MAY31peibCKu/DI=; b=N8ztG0O6+ZSCeYz63g2rkECD4uowbTyq+fUjGMQOQ+4na8oO/pQHXKRfVXP+APLhUb HelL++NlcLFcmNMqUjOlPPW9+VdptY4lKL0KoZHe+Q2P78o2vsIjeoO/yhbfrHBGiWky 1xkTg3KSxhx7epLqw7hRyv87BAwT1ssx70vtJBDv/61WYS1Fqo5Z6dwHXPL6sMbgk3KR /TYGQ1uQ0y9Gv9RvED5HmlbmZzkA79SGi520GoKfHiBk1dVVrtUiILAN+oTAMVSrQaCp ZCvGYwCMr+69GPH7H/PaLAN/5z4ZKH2FsXWoj2dvV+KWrn44xDoTKSCWCOFY2i5QXEfW vpuw== 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:to; bh=PYgj6Hv8ZR8R1aWRKgoyLu22euh1MAY31peibCKu/DI=; b=E59giBxVZ/RdVS9SflIo1P0dY/Cfys2MRbkSLDOfx5qduSdUNIj/1ZDFr9JlmpNNyo BIMX8UwCEPdXCu9PP5WCs3HBIVmMIkHmKmuLVLJbtpN7BFufdmiK5b+3Lf8PEZYk0+hx exAEWKOZFUz87Fp/lQ9sse0GDrsziKwvOSgFZffI/y8/PaFL8Qa9PxWfnD47jdLt0M0x u1tM9ZIOmReUeTZ5b7OZs1Qqs4qtx0kxBUbAszlQUg1zJfWJ8yqoruGZomT6ri9mJqI8 4hFpC4lMHt6vtvzSWNJIAaocMCstEpokQ4v1udGJV54coheeaTwWRqN3C2ki8h6k89Yd v0nA== X-Gm-Message-State: AG10YOS5fRgMUYPksGBRCnNCFX0JULoM8Prw9jtkSrutwru62NQH9cF2ZN2Qmyly3ctCQsBUd7JdCll87UI0GQ== X-Received: by 10.107.19.90 with SMTP id b87mr23457670ioj.11.1456763668077; Mon, 29 Feb 2016 08:34:28 -0800 (PST) In-Reply-To: <1456761964.822300.535132330.33A18241@webmail.messagingengine.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:103731 On Mon, Feb 29, 2016 at 9:06 AM, Random832 wrote: > 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__. You can also make a list that does have an attribute dictionary by subclassing it. >>> class MyList(list): pass ... >>> obj = MyList() >>> obj.test = 'foo'