Class-level variables - a scoping issue
ldo at geek-central.gen.new_zealand
Wed Oct 13 03:06:14 CEST 2010
In message <8hhm9aFblvU1 at mid.individual.net>, Gregory Ewing wrote:
> Lawrence D'Oliveiro wrote:
>> In message <8hfq23FetrU1 at mid.individual.net>, Gregory Ewing wrote:
>>>How would you intend to enforce such a restriction?
>> The same way it’s already enforced.
> I don't see how that's possible, except in a very limited and
> unreliable way. The compiler would have to be able to determine,
> statically, when there was some piece of code that could assign
> to a given instance variable of some instance of a class, and
> arrange for an "unbound attribute error" to be raised if you
> try to reference it before it's been assigned.
If you can’t do it statically, do it dynamically.
More information about the Python-list