empty classes as c structs?
Nick Coghlan
ncoghlan at iinet.net.au
Thu Feb 10 07:59:31 EST 2005
Alex Martelli wrote:
> Nick Coghlan <ncoghlan at iinet.net.au> wrote:
>>For bindings, you could just go with standard Python semantics - normal
>>name binding always happens in the innermost scope, so binding a name in a
>>namespace should happen in the directly referenced namespace. Then you can
>>shadow names from outer scopes, and later regain access to them using
>>'del'.
>
>
> ...which you can't do in "standard Python semantics" - if a name is
> local, it's local throughout. You can't do that with a namespace
> object, which is why I think the best semantics for bindings in that
> case isn't all that clear.
Heh. I was getting two sets of terminology confused. The nested scopes of
functions, and the 'fallback to class' of class instances.
It was the latter I actually meant by 'standard Python semantics' for binding in
a 'chained' namespace:
Py> class C(object):
... x = 1
...
Py> c = C()
Py> c = C()
Py> c.x
1
Py> del c.x
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: 'C' object attribute 'x' is read-only
Py> c.x = 2
Py> c.x
2
Py> del c.x
Py> c.x
1
Py> del c.x
Traceback (most recent call last):
File "<stdin>", line 1, in ?
AttributeError: x
(Huh, I wonder why the error message changed second time around)
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at email.com | Brisbane, Australia
---------------------------------------------------------------
http://boredomandlaziness.skystorm.net
More information about the Python-list
mailing list