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


Groups > comp.lang.python > #111665

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

From Peter Otten <__peter__@web.de>
Newsgroups comp.lang.python
Subject Re: can't add variables to instances of built-in classes
Date 2016-07-20 09:26 +0200
Organization None
Message-ID <mailman.3.1468999586.22221.python-list@python.org> (permalink)
References (12 earlier) <f988e9a1-beba-41f3-bd11-8ed4c7a69a81@googlegroups.com> <CAPTjJmrup=D9pP5buOytY7x1zQYC6Nh-R=WkaXcJBAfbD+_JJA@mail.gmail.com> <mailman.1.1468995572.22221.python-list@python.org> <cadcdba3-61a0-4803-afc5-894d8de4f0cc@googlegroups.com> <nmn92l$4jh$1@ger.gmane.org>

Show all headers | View raw


Lawrence D’Oliveiro wrote:

> On Wednesday, July 20, 2016 at 6:19:45 PM UTC+12, Chris Angelico wrote:
>>
>> On Wed, Jul 20, 2016 at 9:58 AM, Lawrence D’Oliveiro wrote:
>>>
>>> On Wednesday, July 20, 2016 at 9:24:57 AM UTC+12, bream...@gmail.com
>>> wrote:
>>>>
>>>> On Tuesday, July 19, 2016 at 3:54:12 AM UTC+1, Lawrence D’Oliveiro
>>>> wrote:
>>>>>
>>>>> On Tuesday, July 19, 2016 at 11:12:52 AM UTC+12, bream...@gmail.com
>>>>> wrote:
>>>>>>
>>>>>> On Monday, July 18, 2016 at 10:48:15 PM UTC+1, Lawrence D’Oliveiro
>>>>>> wrote:
>>>>>>>
>>>>>>> <https://github.com/ldo/qahirah>
>>>>>>> When you have lots of read/write properties, I find __slots__ to be
>>>>>>> a good idea.
>>>>>>
>>>>>> Please explain why, thank you.
>>>>>
>>>>> I was trying something like
>>>>>
>>>>>     ctx.dashes = ((0.1, 0.03, 0.03, 0.03), 0)
>>>>>
>>>>> and wondering why it wasn’t working...
>>>>
>>>> This makes no sense to me at all.  You appear to be trying to create a
>>>> tuple, which contains a tuple and an integer.  You then say it doesn't
>>>> work, but imply that using __slots__ fixes the problem.  So please
>>>> explain exactly what you were trying to achieve, the exact error you
>>>> got, with the complete traceback, and how using __slots__ fixed the
>>>> problem.
>>>
>>> No traceback. The lines were simply coming out solid, instead of dashed.
>> 
>> And __slots__ fixed the problem how, exactly?
> 
> The Context attribute that controls the dash settings is called “dash”,
> not “dashes”.
> 
>> This sounds like the sort of cargo cult debugging that I'd expect of PHP
>> programmers ("I put addslashes around everything and now it works, so in
>> future I'll use addslashes everywhere"), but around here, we're better
>> than that.
> 
> OK, boss.

pylint can detect candidates for accidental attribute creation:

$ cat attrib.py
class Context:
    def __init__(self):
        self.dashes = None

ctx = Context()
ctx.dasehs = ("foo", "bar")
$ pylint attrib | grep dasehs
W:  6, 4: Attribute 'dasehs' defined outside __init__ (attribute-defined-
outside-init)

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


Thread

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

csiph-web