我有一个包含交易市场信息的python类,但是我只想从整个类中访问一个属性。关于如何做到这一点的任何想法?谢谢。
我已经尝试过了:
class StockDataWebSocket:
web_socket_symbol_list = []
web_socket_instance_dict = {}
def __init__(self, symbol):
self.price = None
self.last_price = 0
symbol = 'test'
instance = StockDataWebSocket(symbol)
StockDataWebSocket.web_socket_symbol_list.append(symbol)
StockDataWebSocket.web_socket_instance_dict[symbol] = instance.last_price
last_price = StockDataWebSocket.web_socket_instance_dict[symbol].last_price
print (last_price)
我想得到0,但我得到:NameError:未定义名称'last_price'