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 whic
On Mon, 08 Aug 2011 03:07:30 +1000
Steven D'Aprano 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 particular case is a class
On Sun, Aug 7, 2011 at 6:07 PM, Steven D'Aprano
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
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 fir
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
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")
Roy Smith wrote:
> In article ,
> 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.
>
> Sounds like you're trying to do
> http://en.wikipedia.org/wiki/Design_by_contract. Which is not
In article ,
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.
Sounds like you're trying to do
http://en.wikipedia.org/wiki/Design_by_contract. Which is not a bad
thing. But, I think
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
wr