Re: Instance of class "object"

2008-05-17 Thread castironpi
On May 17, 1:09 am, Carl Banks <[EMAIL PROTECTED]> wrote: > On May 16, 4:46 am, "甜瓜" <[EMAIL PROTECTED]> wrote: > > > Howdy, > > I wonder why below does not work. > > > a = object() > > a.b = 1# dynamic bind attribute failed... > > > To make it correct, we have to create a new class: >

Re: Instance of class "object"

2008-05-16 Thread Carl Banks
On May 16, 4:46 am, "甜瓜" <[EMAIL PROTECTED]> wrote: > Howdy, > I wonder why below does not work. > > a = object() > a.b = 1# dynamic bind attribute failed... > > To make it correct, we have to create a new class: > class MyClass(object): pass > a = MyClass() > a.b = 1 # OK > > Doe

Re: Instance of class "object"

2008-05-16 Thread Terry Reedy
"Ìð¹Ï" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | > # an efficient 'Pair' class holding two objects | > class Pair(object): | >__slots__ = 'first', 'second' | > | > Instances of Pair take up even less room that 2-element tuples | > because they don't carry the size informat

Re: Instance of class "object"

2008-05-16 Thread Hrvoje Niksic
"甜瓜" <[EMAIL PROTECTED]> writes: >> # an efficient 'Pair' class holding two objects >> class Pair(object): >>__slots__ = 'first', 'second' >> >> Instances of Pair take up even less room that 2-element tuples >> because they don't carry the size information in the object. >> >> Now, if the obje

Re: Instance of class "object"

2008-05-16 Thread castironpi
On May 16, 4:26 am, Peter Otten <[EMAIL PROTECTED]> wrote: > 甜瓜 wrote: > > I wonder why below does not work. > > > a = object() > > a.b = 1# dynamic bind attribute failed... > > The implementation of slots depends on that behaviour: > > http://docs.python.org/ref/slots.html > > > Does t

Re: Instance of class "object"

2008-05-16 Thread castironpi
On May 16, 10:21 am, castironpi <[EMAIL PROTECTED]> wrote: > On May 16, 9:41 am, castironpi <[EMAIL PROTECTED]> wrote: > > > > > > > On May 16, 8:56 am, castironpi <[EMAIL PROTECTED]> wrote: > > > > On May 16, 8:51 am, castironpi <[EMAIL PROTECTED]> wrote: > > > > > On May 16, 4:26 am, Peter Otten

Re: Instance of class "object"

2008-05-16 Thread castironpi
On May 16, 9:41 am, castironpi <[EMAIL PROTECTED]> wrote: > On May 16, 8:56 am, castironpi <[EMAIL PROTECTED]> wrote: > > > > > > > On May 16, 8:51 am, castironpi <[EMAIL PROTECTED]> wrote: > > > > On May 16, 4:26 am, Peter Otten <[EMAIL PROTECTED]> wrote: > > > > > 甜瓜 wrote: > > > > > I wonder

Re: Instance of class "object"

2008-05-16 Thread castironpi
On May 16, 8:56 am, castironpi <[EMAIL PROTECTED]> wrote: > On May 16, 8:51 am, castironpi <[EMAIL PROTECTED]> wrote: > > > > > > > On May 16, 4:26 am, Peter Otten <[EMAIL PROTECTED]> wrote: > > > > 甜瓜 wrote: > > > > I wonder why below does not work. > > > > > a = object() > > > > a.b = 1

Re: Instance of class "object"

2008-05-16 Thread castironpi
On May 16, 4:16 am, Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > "甜瓜" <[EMAIL PROTECTED]> writes: > > Howdy, > > I wonder why below does not work. > > > a = object() > > a.b = 1# dynamic bind attribute failed... > > Because the default object class doesn't have a dict or other > indicatio

Re: Instance of class "object"

2008-05-16 Thread castironpi
On May 16, 8:51 am, castironpi <[EMAIL PROTECTED]> wrote: > On May 16, 4:26 am, Peter Otten <[EMAIL PROTECTED]> wrote: > > > 甜瓜 wrote: > > > I wonder why below does not work. > > > > a = object() > > > a.b = 1# dynamic bind attribute failed... > > > The implementation of slots depends o

Re: Instance of class "object"

2008-05-16 Thread castironpi
On May 16, 4:26 am, Peter Otten <[EMAIL PROTECTED]> wrote: > 甜瓜 wrote: > > I wonder why below does not work. > > > a = object() > > a.b = 1# dynamic bind attribute failed... > > The implementation of slots depends on that behaviour: > > http://docs.python.org/ref/slots.html > > > Does t

Re: Instance of class "object"

2008-05-16 Thread 甜瓜
2008/5/16 Hrvoje Niksic <[EMAIL PROTECTED]>: > "甜瓜" <[EMAIL PROTECTED]> writes: > >> Howdy, >> I wonder why below does not work. >> >> a = object() >> a.b = 1# dynamic bind attribute failed... > > Because the default object class doesn't have a dict or other > indication of state. It's

Re: Instance of class "object"

2008-05-16 Thread Peter Otten
甜瓜 wrote: > I wonder why below does not work. > > a = object() > a.b = 1# dynamic bind attribute failed... The implementation of slots depends on that behaviour: http://docs.python.org/ref/slots.html > Does this strange behavior break the LSP (Liskov substitution principle)? Can y

Re: Instance of class "object"

2008-05-16 Thread Hrvoje Niksic
"甜瓜" <[EMAIL PROTECTED]> writes: > Howdy, > I wonder why below does not work. > > a = object() > a.b = 1# dynamic bind attribute failed... Because the default object class doesn't have a dict or other indication of state. It's a "pure" Python object whose only visible properties are

Re: Instance of class "object"

2008-05-16 Thread Ben Finney
"甜瓜" <[EMAIL PROTECTED]> writes: > Howdy, > I wonder why below does not work. > > a = object() > a.b = 1# dynamic bind attribute failed... > > To make it correct, we have to create a new class: > class MyClass(object): pass > a = MyClass() > a.b = 1 # OK It's annoyingly diffic

Instance of class "object"

2008-05-16 Thread 甜瓜
Howdy, I wonder why below does not work. a = object() a.b = 1# dynamic bind attribute failed... To make it correct, we have to create a new class: class MyClass(object): pass a = MyClass() a.b = 1 # OK Does this strange behavior break the LSP (Liskov substitution principle)?