I have this–
JavaScript
x
6
1
class A(object):
2
def __init__(self):
3
self.b = 1
4
self.c = 2
5
self.d = 4
6
I want —
JavaScript
1
9
1
class A(object):
2
def __init__(self):
3
self.b = 1
4
self.c = 2
5
self.d = 4
6
7
def do_nothing(self):
8
a={'b':1,'c':2,'d':4}
9
how to use instance variable as key value in another r method
Advertisement
Answer
Magic methods __dict__
can help you
JavaScript
1
14
14
1
class A(object):
2
3
def __init__(self):
4
self.a = 1
5
self.b = 2
6
self.c = 3
7
8
def test(self):
9
print(self.__dict__)
10
11
a = A()
12
a.test()
13
14
Output
JavaScript
1
2
1
{'a': 1, 'b': 2, 'c': 3}
2