From: faassen at pop.vet.uu.nl (Martijn Faassen)
Date: Mon, 26 Apr 1999 13:44:04 +0200
Subject: Emulating C++ coding style
References: <371F8FB7.92CE674F@pk.highway.ne.jp> <371F9D0C.4F1205BB@pop.vet.uu.nl> <7foe7r$15mi$1@nntp6.u.washington.edu>
Message-ID: <37245184.3AADF34D@pop.vet.uu.nl>
Content-Length: 1043
X-UID: 1354                                                  

Donn Cave wrote:
> 
> Martijn Faassen <faassen at pop.vet.uu.nl> writes:
> | A static value can be created like this (besides using a global variable
> | in a module):
> |
> | class Foo:
> |    self.shared = 1
> |
> |    def __init__(self):
> |        print self.shared
> 
> Just a nit-pick on this particular item - I tried that already, a
> couple of days ago, so I know it won't work!  You meant to say,
> 
>   class Foo:
>       shared = 1

Whoops, yes, that makes sense. :) Sorry.

> Now a couple of further observations.  Per the question, yes, that
> variable ("attribute") is accessible in the class scope:
> 
>    print Foo.shared
> 
> As well as in the instance scope, as shown in Martijn's example.

[snip surprise]
> It's not much like C++ here, but it's uncanny how it reeks of Python!
> Namespaces, references!

Indeed. Not having used that class attribute trick often myself, I
wasn't aware of this surprising behavior. I suppose in order to get the
C++ behavior it's best to use a module global variable.

Regards,

Martijn




