我有這個 -
class A(object):
def __init__(self):
self.b = 1
self.c = 2
self.d = 4
我想要 -
class A(object):
def __init__(self):
self.b = 1
self.c = 2
self.d = 4
def do_nothing(self):
a={'b':1,'c':2,'d':4}
如何在另一個 r 方法中使用實體變數作為鍵值
uj5u.com熱心網友回復:
神奇的方法__dict__可以幫助你
class A(object):
def __init__(self):
self.a = 1
self.b = 2
self.c = 3
def test(self):
print(self.__dict__)
a = A()
a.test()
輸出
{'a': 1, 'b': 2, 'c': 3}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/454583.html
上一篇:連接地圖中的所有欄位
