force variable declaration?
Alan Kennedy
alanmk at hotmail.com
Thu Oct 10 07:43:36 EDT 2002
Peter Rams wrote:
> thanks for your answer, I meant something like this:
>
> counter = 0
> while counter < 100:
> conuter = counter + 1
In Python 2.2, objects can have the "__slots__" attribute, which
contains a list of permissible attribute names. For example
class counter(object):
__slots__ = ['count']
def __init__(self):
self.conut = 0
>>>mycounter = counter()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 4, in __init__
AttributeError: 'counter' object has no attribute 'conut'
In order for the __slots__ attribute to work, the class has to be a "new
style class". To ensure this, simply inherit from the "object" class,
which was also introduced in python 2.2.
More from here
http://www.python.org/doc/2.2.1/whatsnew/sect-rellinks.html#SECTION000340000000000000000
Regards,
--
alan kennedy
----------------------------------------------
check http headers here: xhaus.com/headers
email alan: xhaus.com/mailto/alan
More information about the Python-list
mailing list