Kevac Marko a écrit :
> On Nov 10, 8:39 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>> Don't think so. It's a surprise for many but then class attributes are
>> not that common in code or they even use this "gotcha" for
>> immutable default values. As long a the value isn't changed th
Donn Ingle a écrit :
(about class attributes, instance attributes and lookup rules)
> Okay, I sort of see that. It's not a property
For clarity, better s/property/attribute/ here. In Python, property is a
builtin class used for computed attributes.
> of 'j' so it looks upwards
> into the class.
> Kevac Marko <[EMAIL PROTECTED]> writes:
> > When changing default value, is there any way to change class
> > attribute and all referenced attributes too?
>
> > class M:
> > name = u"Marko"
>
> > a, b = M(), M()
> > a.name = u"Kevac"
> > print M.name, a.name, b.name
> > -> Marko Kevac Marko
>
Kevac Marko <[EMAIL PROTECTED]> writes:
> When changing default value, is there any way to change class
> attribute and all referenced attributes too?
>
> class M:
> name = u"Marko"
>
> a, b = M(), M()
> a.name = u"Kevac"
> print M.name, a.name, b.name
> -> Marko Kevac Marko
>
> Is there any w
On Nov 10, 8:39 pm, Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote:
>
> Don't think so. It's a surprise for many but then class attributes are
> not that common in code or they even use this "gotcha" for
> immutable default values. As long a the value isn't changed the default
> value is just
Very interesting reply. I must ask a few questions, interleaved:
> If you mean that all instances of Class Canvas and Thing will share
> the *same* Stack, I think we can do it kind of like this:
What's the difference between "same Stack" and "same instance of Stack"? I
thought I knew what an insta
Donn Ingle a écrit :
(snip)
> I have been hearing about "new classes" for a while but there's no clarity
> in the Python docs (that I can find).
Then you perhaps should have a closer look at the entries in the
'documentation' sub-menu of python.org !-)
Anyway, here's a direct link:
http://python
On 11 10 , 10 01 , Donn Ingle <[EMAIL PROTECTED]> wrote:
>
> > def pop(self):
> > item = self.list[-1]
> > del self.list[-1]
> > return item
>
> Is there some reason you do all that and not a self.list.pop(0)?
>
Hi.
There are no special reasons I do it that way.
Just
On Sat, 10 Nov 2007 17:39:04 +, Marc 'BlackJack' Rintsch wrote:
> On Sat, 10 Nov 2007 18:53:08 +0200, Donn Ingle wrote:
print b.ref.attribute # print "haschanged"
print j.ref.attribute #prints "original value"
## If it changed and an attribute of the Class, then
## wh
Thanks for your time and patience Marc, that was some hotshot ascii art.
I'll have to take some time to digest this.
\d
--
http://mail.python.org/mailman/listinfo/python-list
On Sat, 10 Nov 2007 18:53:08 +0200, Donn Ingle wrote:
> Included again for clarity:
>>> class Test:
>>> attribute = "original value"
>>>
>>> class Bob:
>>> def __init__(self):
>>> self.ref = Test()
>>>
>>> class Jim:
>>> def __init__(self):
>>> self.ref =
Included again for clarity:
>> class Test:
>> attribute = "original value"
>>
>> class Bob:
>> def __init__(self):
>> self.ref = Test()
>>
>> class Jim:
>> def __init__(self):
>> self.ref = Test()
>>
>> b = Bob()
>> j = Jim()
>>
>> print b.ref.att
On Sat, 10 Nov 2007 17:00:13 +0200, Donn Ingle wrote:
>> The first creates an attribute of the class, the second creates an
>> attribute in the instance.
>
> Given that, can you clarify this:
>
> class Test:
> attribute = "original value"
>
> class Bob:
> def __init__(self):
>
> The first creates an attribute of the class, the second creates an
> attribute in the instance.
Given that, can you clarify this:
class Test:
attribute = "original value"
class Bob:
def __init__(self):
self.ref = Test()
class Jim:
def __init__(self):
se
Donn Ingle <[EMAIL PROTECTED]> wrote:
>> class Stack:
>> list = []
> Okay, this has me a little weirded-out. How is this different from
> putting it in:
> def __init__(self):
> self.list = []
> ?
> I see from tests that it is different, but I don't quite grok it. Who
> owns the list r
Very interesting reply. I must ask a few questions, interleaved:
> If you mean that all instances of Class Canvas and Thing will share
> the *same* Stack, I think we can do it kind of like this:
What's the difference between "same Stack" and "same instance of Stack"? I
thought I knew what an insta
On 11 10 , 5 48 , Donn Ingle <[EMAIL PROTECTED]> wrote:
> ## == API in another module perhaps ===
> Class Stack:
> def push(self,stuff):
> pass
>
> Class Canvas:
> def do(self):
> s.push("data") #I don't feel right about 's' here.
>
> Class Thing:
> def buzz(self):
> print s.pop(0)
>
>
> I guess you mean "instances", not "classes".
Yes.
> Err...Perhaps a dumb question, but what about passing the "common
> objects" to initializers ?
> s = Stack()
> c = Canvas(s)
> t = Thing(s)
Okay, I see where you're going. It's better than what I have at the moment.
Thanks.
\d
--
http://m
Donn Ingle a écrit :
>>>I thought this might be a case for multiple inheritance
>>
>>???
>
> Well, in terms of having Canvas and Thing inherit from Stack and thereby
> (somehow, not sure how) they would both have access to Stack.stack (a list)
>
>
>>wrt/ all Thing instances having to refer to a
>> I thought this might be a case for multiple inheritance
> ???
Well, in terms of having Canvas and Thing inherit from Stack and thereby
(somehow, not sure how) they would both have access to Stack.stack (a list)
> wrt/ all Thing instances having to refer to a same Stack instance,
> there's a pr
Donn Ingle a écrit :
> Hi,
> I'm getting myself really confused. I have three classes. Two of them need
> to reference the third, like so:
>
> Canvas ---> Stack <--- Thing
>
> I am doing this right now:
>
> s = Stack()
>
> And then within I am referring directly to the global
> variable 's' (a
21 matches
Mail list logo