Re: Restricted attribute writing

2011-08-10 Thread Thomas Jollans
On 07/08/11 17:35, John O'Hagan wrote: I'm looking for good ways to ensure that attributes are only writable such that they retain the characteristics the class requires. My particular case is a class attribute which is initialised as a list of lists of two integers, the first of which is

Restricted attribute writing

2011-08-07 Thread John O'Hagan
I'm looking for good ways to ensure that attributes are only writable such that they retain the characteristics the class requires. My particular case is a class attribute which is initialised as a list of lists of two integers, the first of which is a modulo remainder. I need to be able to

Re: Restricted attribute writing

2011-08-07 Thread Roy Smith
In article mailman.2010.1312731312.1164.python-l...@python.org, John O'Hagan resea...@johnohagan.com wrote: I'm looking for good ways to ensure that attributes are only writable such that they retain the characteristics the class requires. Sounds like you're trying to do

Re: Restricted attribute writing

2011-08-07 Thread Steven D'Aprano
Roy Smith wrote: In article mailman.2010.1312731312.1164.python-l...@python.org, John O'Hagan resea...@johnohagan.com wrote: I'm looking for good ways to ensure that attributes are only writable such that they retain the characteristics the class requires. Sounds like you're trying to

Re: Restricted attribute writing

2011-08-07 Thread Rafael Durán Castañeda
I think you might use a tuple instead of a list for OrderElement, that would make much easier your code: class OrderElement(tuple): def __new__(cls, x, y): if not isinstance(x, int) or not isinstance(y, int): raise TypeError(Order element must receives two integers)

Re: Restricted attribute writing

2011-08-07 Thread Rafael Durán Castañeda
The assert on Order should be an if ... raise, like OrderElement, sorry for the mistake and repost El 7 de agosto de 2011 18:53, Rafael Durán Castañeda rafadurancastan...@gmail.com escribió: I think you might use a tuple instead of a list for OrderElement, that would make much easier your

Re: Restricted attribute writing

2011-08-07 Thread Steven D'Aprano
John O'Hagan wrote: I'm looking for good ways to ensure that attributes are only writable such that they retain the characteristics the class requires. That's what properties are for. My particular case is a class attribute which is initialised as a list of lists of two integers, the first

Re: Restricted attribute writing

2011-08-07 Thread Chris Angelico
On Sun, Aug 7, 2011 at 6:07 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: class ThingWithTwoIntegers(object): I'm not a lisp expert, but this might well be called a cons cell. Or a pair. ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Restricted attribute writing

2011-08-07 Thread John O'Hagan
On Mon, 08 Aug 2011 03:07:30 +1000 Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: John O'Hagan wrote: I'm looking for good ways to ensure that attributes are only writable such that they retain the characteristics the class requires. That's what properties are for. My