K
Kenneth McDonald
I've recently used subclasses of the builtin str class to good effect.
However, I've been unable to do the following:
1) Call the constructor with a number of arguments other than
the number of arguments taken by the 'str' constructor.
2) Create and use instance variables (eg. 'self.x=1') in
the same way that I can in a 'normal' class.
As an example of what I mean, here's a short little session:
.... def __init__(self, a, b):
.... str.__init__(a)
.... self.b = b
.... Traceback (most recent call last):
(hmm, on reflection, I shouldn't have used 'a' as a
parameter to __init__--but that's merely bad
style, not the cause of the error )
.... def __init__(self, x):
.... str.__init__(x)
....
Is it possible to circumvent the above restrictions?
Thanks,
Ken
However, I've been unable to do the following:
1) Call the constructor with a number of arguments other than
the number of arguments taken by the 'str' constructor.
2) Create and use instance variables (eg. 'self.x=1') in
the same way that I can in a 'normal' class.
As an example of what I mean, here's a short little session:
.... def __init__(self, a, b):
.... str.__init__(a)
.... self.b = b
.... Traceback (most recent call last):
(hmm, on reflection, I shouldn't have used 'a' as a
parameter to __init__--but that's merely bad
style, not the cause of the error )
.... def __init__(self, x):
.... str.__init__(x)
....
Is it possible to circumvent the above restrictions?
Thanks,
Ken