M
marekw2143
Hi,
I have one class (A) that has defined method createVars. I would like
to add that method to class B
The code looks like this:
class A(object):
def createVars(self):
self.v1 = 1
self.v2 = 3
pass
class B(object):
pass
I don't want to use inheritance (because class A has many methods
defined that class B doesn't need).
When I try the folloowing:
B.createVars = C.createVars
B().createVars()
then the following error occurs:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unbound method createVars() must be called with A instance
as first argument (got nothing instead)
When I try to add the createVars method to instance of B:
Then the following error raises:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unbound method createVars() must be called with A instance
as first argument (got B instance instead)
How can I solve this problem?
Regards,
Marek
I have one class (A) that has defined method createVars. I would like
to add that method to class B
The code looks like this:
class A(object):
def createVars(self):
self.v1 = 1
self.v2 = 3
pass
class B(object):
pass
I don't want to use inheritance (because class A has many methods
defined that class B doesn't need).
When I try the folloowing:
B.createVars = C.createVars
B().createVars()
then the following error occurs:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unbound method createVars() must be called with A instance
as first argument (got nothing instead)
When I try to add the createVars method to instance of B:
Then the following error raises:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unbound method createVars() must be called with A instance
as first argument (got B instance instead)
How can I solve this problem?
Regards,
Marek