I have a class C. I would like to instantiate this class with one argument. Let's call that argument d. So I would like to do myC = C(d=5). C should also have another variable called e. e's value should be set to d on instantiation of the class.
So I wrote this:
>>> class C:
... def __init__(self,d):
... self.d = d
... e = d
...
But that gives me the following error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in C
NameError: name 'd' is not defined
Ok fine, So I will try something slightly different:
>>> class C:
... def __init__(self,d):
... self.d = d
... e = self.d
...
But that gives me this error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in C
NameError: name 'self' is not defined
So how should I do what I'm trying to do?? This should be very simple.