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


Groups > comp.lang.python > #111567 > unrolled thread

can't add variables to instances of built-in classes

Started byKent Tong <kent.tong.mo@gmail.com>
First post2016-07-17 03:57 -0700
Last post2016-07-17 04:53 -0700
Articles 11 on this page of 31 — 9 participants

Back to article view | Back to comp.lang.python


Contents

  can't add variables to instances of built-in classes Kent Tong <kent.tong.mo@gmail.com> - 2016-07-17 03:57 -0700
    Re: can't add variables to instances of built-in classes Peter Otten <__peter__@web.de> - 2016-07-17 13:40 +0200
      Re: can't add variables to instances of built-in classes Wilson Ong <wilsonokw@gmail.com> - 2016-07-17 04:50 -0700
        Re: can't add variables to instances of built-in classes Chris Angelico <rosuav@gmail.com> - 2016-07-17 22:02 +1000
        Re: can't add variables to instances of built-in classes Steven D'Aprano <steve@pearwood.info> - 2016-07-18 01:04 +1000
          Re: can't add variables to instances of built-in classes Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-17 20:00 -0700
            Re: can't add variables to instances of built-in classes Peter Otten <__peter__@web.de> - 2016-07-18 09:38 +0200
              Re: can't add variables to instances of built-in classes Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-18 14:48 -0700
                Re: can't add variables to instances of built-in classes breamoreboy@gmail.com - 2016-07-18 16:12 -0700
                  Re: can't add variables to instances of built-in classes Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-18 19:53 -0700
                    Re: can't add variables to instances of built-in classes breamoreboy@gmail.com - 2016-07-19 14:24 -0700
                      Re: can't add variables to instances of built-in classes Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-19 16:58 -0700
                        Re: can't add variables to instances of built-in classes Chris Angelico <rosuav@gmail.com> - 2016-07-20 16:19 +1000
                          Re: can't add variables to instances of built-in classes Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-19 23:45 -0700
                            Re: can't add variables to instances of built-in classes Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-07-20 17:22 +1000
                            Re: can't add variables to instances of built-in classes Peter Otten <__peter__@web.de> - 2016-07-20 09:26 +0200
                              Re: can't add variables to instances of built-in classes Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-20 01:50 -0700
                                Re: can't add variables to instances of built-in classes Peter Otten <__peter__@web.de> - 2016-07-20 11:15 +0200
                                  Re: can't add variables to instances of built-in classes Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-20 15:11 -0700
                                    Re: can't add variables to instances of built-in classes Chris Angelico <rosuav@gmail.com> - 2016-07-21 12:29 +1000
                                      Re: can't add variables to instances of built-in classes Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-08-03 19:34 -0700
                                        Re: can't add variables to instances of built-in classes Chris Angelico <rosuav@gmail.com> - 2016-08-04 13:00 +1000
                                          Re: can't add variables to instances of built-in classes Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-08-04 16:57 -0700
                                    Re: can't add variables to instances of built-in classes Steven D'Aprano <steve@pearwood.info> - 2016-07-21 12:48 +1000
                                Re: can't add variables to instances of built-in classes Steven D'Aprano <steve@pearwood.info> - 2016-07-20 22:10 +1000
                                  Re: can't add variables to instances of built-in classes Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-20 14:48 -0700
                                    Re: can't add variables to instances of built-in classes breamoreboy@gmail.com - 2016-07-20 18:04 -0700
                                      Re: can't add variables to instances of built-in classes Peter Otten <__peter__@web.de> - 2016-07-21 08:59 +0200
                Re: can't add variables to instances of built-in classes Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-20 02:10 -0700
        Re: can't add variables to instances of built-in classes Ethan Furman <ethan@stoneleaf.us> - 2016-07-18 06:10 -0700
    Re: can't add variables to instances of built-in classes Kent Tong <kent.tong.mo@gmail.com> - 2016-07-17 04:53 -0700

Page 2 of 2 — ← Prev page 1 [2]


#112315

FromLawrence D’Oliveiro <lawrencedo99@gmail.com>
Date2016-08-03 19:34 -0700
Message-ID<c4b6e08d-a38b-4404-8bc3-b0ed97a6c48e@googlegroups.com>
In reply to#111688
On Thursday, July 21, 2016 at 2:29:53 PM UTC+12, Chris Angelico wrote:

> Using __slots__ basically takes your object down to the level of a
> Java one.

Is Java like a bogeyman you use to scare people with if they don’t write Python code the way you like it?

[toc] | [prev] | [next] | [standalone]


#112316

FromChris Angelico <rosuav@gmail.com>
Date2016-08-04 13:00 +1000
Message-ID<mailman.159.1470280024.6033.python-list@python.org>
In reply to#112315
On Thu, Aug 4, 2016 at 12:34 PM, Lawrence D’Oliveiro
<lawrencedo99@gmail.com> wrote:
> On Thursday, July 21, 2016 at 2:29:53 PM UTC+12, Chris Angelico wrote:
>
>> Using __slots__ basically takes your object down to the level of a
>> Java one.
>
> Is Java like a bogeyman you use to scare people with if they don’t write Python code the way you like it?

LOL! Not really; it's just that Java's objects are way less featured
than Python's.

ChrisA

[toc] | [prev] | [next] | [standalone]


#112356

FromLawrence D’Oliveiro <lawrencedo99@gmail.com>
Date2016-08-04 16:57 -0700
Message-ID<b4ea91b0-d6bf-45b9-9efe-49bc57ca489f@googlegroups.com>
In reply to#112316
On Thursday, August 4, 2016 at 3:07:17 PM UTC+12, Chris Angelico wrote:
> On Thu, Aug 4, 2016 at 12:34 PM, Lawrence D’Oliveiro wrote:
>> On Thursday, July 21, 2016 at 2:29:53 PM UTC+12, Chris Angelico wrote:
>>
>>> Using __slots__ basically takes your object down to the level of a
>>> Java one.
>>
>> Is Java like a bogeyman you use to scare people with if they don’t write
>> Python code the way you like it?
> 
> LOL! Not really; it's just that Java's objects are way less featured
> than Python's.

Using Java as an example of how it can keep you out of trouble where Python won’t is fine; using it as a stick to commit personal attacks on people is not.

[toc] | [prev] | [next] | [standalone]


#111689

FromSteven D'Aprano <steve@pearwood.info>
Date2016-07-21 12:48 +1000
Message-ID<57903817$0$1602$c3e8da3$5496439d@news.astraweb.com>
In reply to#111684
On Thu, 21 Jul 2016 08:11 am, Lawrence D’Oliveiro wrote:

> On Wednesday, July 20, 2016 at 9:16:30 PM UTC+12, Peter Otten wrote:
>>
>> Lawrence D’Oliveiro wrote:
>> 
>>> On Wednesday, July 20, 2016 at 7:26:36 PM UTC+12, Peter Otten wrote:
>>> 
>>>> pylint can detect candidates for accidental attribute creation:
>>> 
>>> And __slots__ will prevent them outright.
>> 
>> And attributes added intentionally.
> 
> You mean, being able to dynamically add new attributes to an object?
> 
> Probably not a good idea to mix that with read/write properties...

Why not?


If you're going to make a comment, would you please include some actual
significant information in your post? Dropping obtuse hints and incomplete
answers are not useful, and they give the strong impression that you are
only replying in order to gain a smug sense of superiority rather than to
disseminate knowledge and understanding.

Remember that other people cannot know the thought in your mind, they can
only judge by the actual words you have written, and if those words
standing alone do not explain your thinking, then people will:

(1) fail to understand the information you are trying to pass on;

(2) imagine that you are intentionally trying to be difficult; and

(3) characterise you as an insufferable, pretentious wanker who thinks that
giving mysterious, unintelligible responses makes him out to be ever-so
smarter than everyone else.


Poor quality answer:

"Probably not a good idea to mix that with read/write properties..."

Better:

"Probably not a good idea to mix that with read/write properties, for the
following reasons: [succinct explanation of the reasons why one should
avoid mixing ordinary attributes and properties]. Here's a longer
discussion [link to URL]."





-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

[toc] | [prev] | [next] | [standalone]


#111669

FromSteven D'Aprano <steve@pearwood.info>
Date2016-07-20 22:10 +1000
Message-ID<578f6a4f$0$22142$c3e8da3$5496439d@news.astraweb.com>
In reply to#111666
On Wed, 20 Jul 2016 06:50 pm, Lawrence D’Oliveiro wrote:

> On Wednesday, July 20, 2016 at 7:26:36 PM UTC+12, Peter Otten wrote:
> 
>> pylint can detect candidates for accidental attribute creation:
> 
> And __slots__ will prevent them outright.


As well as those added intentionally.

Sometimes I wonder what it is that you see in Python and why you use it.
You're frequently complaining about features of the language. You go out of
your way to write in the style of Java/C/whatever in Python, which means
you get all the disadvantages of writing verbose and inflexible static
Java/C/whatever PLUS the inefficiency of dynamic Python, so the worst of
both worlds.

I genuinely don't see what you get out of using Python. Would you care to
explain? There must be something you like about it, even if it isn't the
ability to add attributes to (nearly) arbitrary objects without declaring
them, or the duck-typing of booleans.




-- 
Steven
“Cheer up,” they said, “things could be worse.” So I cheered up, and sure
enough, things got worse.

[toc] | [prev] | [next] | [standalone]


#111683

FromLawrence D’Oliveiro <lawrencedo99@gmail.com>
Date2016-07-20 14:48 -0700
Message-ID<fda0685c-1408-45f5-ad3c-76dbec2878ed@googlegroups.com>
In reply to#111669
On Thursday, July 21, 2016 at 12:11:09 AM UTC+12, Steven D'Aprano wrote:

> [long irrelevant rant deleted]

Just because I pointed out what a load of nonsense you were spouting about __slots__, by giving a counterexample of their usefulness? Man, your pride must be hurt...

[toc] | [prev] | [next] | [standalone]


#111686

Frombreamoreboy@gmail.com
Date2016-07-20 18:04 -0700
Message-ID<03ce3d45-aadb-46df-8d64-4e33ffd44825@googlegroups.com>
In reply to#111683
On Wednesday, July 20, 2016 at 10:48:23 PM UTC+1, Lawrence D’Oliveiro wrote:
> On Thursday, July 21, 2016 at 12:11:09 AM UTC+12, Steven D'Aprano wrote:
> 
> > [long irrelevant rant deleted]
> 
> Just because I pointed out what a load of nonsense you were spouting about __slots__, by giving a counterexample of their usefulness? Man, your pride must be hurt...

I hereby request that the moderators take this idiot offline as he's managed to insult two highly respected members of this community in no time at all, those of course being Steven D'Aprano and Peter Otten.

Kindest regards.

Mark Lawrence.

[toc] | [prev] | [next] | [standalone]


#111702

FromPeter Otten <__peter__@web.de>
Date2016-07-21 08:59 +0200
Message-ID<mailman.19.1469084366.22221.python-list@python.org>
In reply to#111686
breamoreboy@gmail.com wrote:

> I hereby request that the moderators take this idiot offline as he's

Mark, please behave yourself.

[toc] | [prev] | [next] | [standalone]


#111667

FromLawrence D’Oliveiro <lawrencedo99@gmail.com>
Date2016-07-20 02:10 -0700
Message-ID<32fea203-d689-448b-91ac-0229c7a20b10@googlegroups.com>
In reply to#111616
On Tuesday, July 19, 2016 at 9:48:15 AM UTC+12, I wrote:

> When you have lots of read/write properties, I find __slots__ to be a good
> idea.

Let me amend that. When you have *any* read/write properties, I find __slots__ to be a good idea.

[toc] | [prev] | [next] | [standalone]


#111605

FromEthan Furman <ethan@stoneleaf.us>
Date2016-07-18 06:10 -0700
Message-ID<mailman.74.1468847389.2307.python-list@python.org>
In reply to#111571
On 07/17/2016 04:50 AM, 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?

One of the very nice things about Python is being able to fiddle with objects, both
for debugging and for extending.  One of the ways that's accomplished is by adding
attributes to instances, but when __slots__ is defined that ability is lost, which
can make using/debugging those types of objects harder.

__slots__ is a memory optimization, and like most optimazations you shouldn't use
it until you know you need it.

--
~Ethan~

[toc] | [prev] | [next] | [standalone]


#111572

FromKent Tong <kent.tong.mo@gmail.com>
Date2016-07-17 04:53 -0700
Message-ID<d39cdf81-4741-4278-bce6-45db592c7728@googlegroups.com>
In reply to#111567
Hi Peter,

Thanks a lot for your excellent explanation!

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.python


csiph-web