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


Groups > comp.lang.python > #103726

Re: Dynamic object attribute creation

From Random832 <random832@fastmail.com>
Newsgroups comp.lang.python
Subject Re: Dynamic object attribute creation
Date 2016-02-29 11:06 -0500
Message-ID <mailman.19.1456761968.20602.python-list@python.org> (permalink)
References <56d46597$0$22756$426a74cc@news.free.fr>

Show all headers | 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