Python class __init__(mandatory arguments?)
Lee John Moore
leej at dsl.pipex.com
Sun Jun 15 19:02:26 EDT 2003
Just for confirmation really: When I create a custom class, is
it *really* true that def __init__() arguments can only ever be
optional? Eg:
class MyClass:
param1 = None
param2 = None
def __init__(self, param1, param2):
param1 = self.param1
param2 = self.param2
myinstance1 = MyClass()
myinstance2 = MyClass("Hello", "World")
[snip]
I'm really unhappy that myinstance1 is allowed. ;-)
I'm so accustomed to constructor arguments being mandatory in
C++ & OP classes....and yes, yes, I realise __init__() is not a
constructor (even though it looks like one), but if there's a
way I can *force* arguments upon class instantiation, I'd like
to know about it. :-)
--
"However far you may travel in this world, you
will still occupy the same volume of space."
- Traditional Ur-Bororo saying
More information about the Python-list
mailing list