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

2016-08-04 Thread Lawrence D’Oliveiro
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. >>

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

2016-08-03 Thread Chris Angelico
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 >

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

2016-08-03 Thread Lawrence D’Oliveiro
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? -- https://mail.python.org/mailman/li

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

2016-07-21 Thread Peter Otten
breamore...@gmail.com wrote: > I hereby request that the moderators take this idiot offline as he's Mark, please behave yourself. -- https://mail.python.org/mailman/listinfo/python-list

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

2016-07-20 Thread Steven D'Aprano
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 attrib

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

2016-07-20 Thread Chris Angelico
On Thu, Jul 21, 2016 at 8: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 attri

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

2016-07-20 Thread breamoreboy
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 cou

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

2016-07-20 Thread Lawrence D’Oliveiro
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. >

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

2016-07-20 Thread Lawrence D’Oliveiro
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... -- https://mail.python

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

2016-07-20 Thread Steven D'Aprano
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

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

2016-07-20 Thread Peter Otten
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. -- https://mail.python.org/mailman/listinfo/

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

2016-07-20 Thread Lawrence D’Oliveiro
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. -- https://mail.python.org/mailman/listinfo/python-list

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

2016-07-20 Thread Lawrence D’Oliveiro
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. -- https://mail.python.org/mailman/listinfo/python-list

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

2016-07-20 Thread Peter Otten
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

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

2016-07-20 Thread Steven D'Aprano
On Wednesday 20 July 2016 16:45, Lawrence D’Oliveiro wrote: > I was trying something like > > ctx.dashes = ((0.1, 0.03, 0.03, 0.03), 0) > > and wondering why it wasn’t working... And so are we. Since you've already solved the problem, maybe you could enlighten us? T

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

2016-07-19 Thread Lawrence D’Oliveiro
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:

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

2016-07-19 Thread Chris Angelico
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 wrot

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

2016-07-19 Thread Lawrence D’Oliveiro
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

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

2016-07-19 Thread breamoreboy
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: > >> > >> > >> When you have lots

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

2016-07-18 Thread Lawrence D’Oliveiro
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: >> >> >> When you have lots of read/write properties, I find __slots__ to be a good >> idea. > > Please explain

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

2016-07-18 Thread Lawrence D’Oliveiro
On Monday, July 18, 2016 at 7:39:09 PM UTC+12, Peter Otten wrote: > Lawrence D’Oliveiro wrote: > >> I find __slots__ very useful. I have them right through my Qahirah classes >> , for example. > > Or is there something I didn't think of that makes them useful for y

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

2016-07-18 Thread Ethan Furman
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 attr

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

2016-07-18 Thread Peter Otten
Lawrence D’Oliveiro wrote: > On Monday, July 18, 2016 at 3:04:13 AM UTC+12, Steven D'Aprano wrote: > >> __slots__ is not obsolete, but 99% of the time you shouldn't bother with >> it. > > I find __slots__ very useful. I have them right through my Qahirah classes >

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

2016-07-17 Thread Lawrence D’Oliveiro
On Monday, July 18, 2016 at 3:04:13 AM UTC+12, Steven D'Aprano wrote: > __slots__ is not obsolete, but 99% of the time you shouldn't bother with it. I find __slots__ very useful. I have them right through my Qahirah classes , for example. -- https://mail.python.o

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

2016-07-17 Thread Steven D'Aprano
On Sun, 17 Jul 2016 09:50 pm, 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 e

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

2016-07-17 Thread Chris Angelico
On Sun, Jul 17, 2016 at 9:50 PM, 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 e

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

2016-07-17 Thread Kent Tong
Hi Peter, Thanks a lot for your excellent explanation! -- https://mail.python.org/mailman/listinfo/python-list

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

2016-07-17 Thread Wilson Ong
> 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? -- https://mail.python.org

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

2016-07-17 Thread Peter Otten
Kent Tong wrote: > Hi, > > I can add new variables to user-defined classes like: > class Test: > ... pass > ... a=Test() a.x=100 > > but it doesn't work if the instances belong to a built-in class such as > str or list: > a='abc' a.x=100 > Traceback (most recent c

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

2016-07-17 Thread Kent Tong
Hi, I can add new variables to user-defined classes like: >>> class Test: ... pass ... >>> a=Test() >>> a.x=100 but it doesn't work if the instances belong to a built-in class such as str or list: >>> a='abc' >>> a.x=100 Traceback (most recent call last): File "", line 1, in Attribu