class variable declarations...
Alan Kennedy
alanmk at hotmail.com
Mon Jun 16 10:13:34 EDT 2003
Lee John Moore wrote:
> My biggest mental block with python seems to be undeclared variables. A
> declaration block alone is handy for reference. Statically typed
> languages have really messed me up. Is there a therapy group for
> refugees? ;-)
How about this, using new style classes:-
class SpeedTouchComm(object):
"Interface with the SpeedTouch router"
__slots__ = ['connect', 'uid', 'pwd', 'rtuid', 'rtpwd']
def __init__(self, connect, uid, pwd, rtuid, rtpwd):
self.connect = connect
self.uid = uid
self.pwd = pwd
self.rtuid = rtuid
self.rtpwd = rtpwd
self.namenotinslots = ''
>>> o = SpeedTouchComm(1,2,3,4,5)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 12, in __init__
AttributeError: 'SpeedTouchComm' object has no attribute 'namenotinslots'
>>>
There are more sophisticated ways to manipulate object instances and data, for
example using descriptors or __metaclasses__. But I think that this mostly
solves your difficulty.
HTH,
--
alan kennedy
-----------------------------------------------------
check http headers here: http://xhaus.com/headers
email alan: http://xhaus.com/mailto/alan
More information about the Python-list
mailing list