My Code:
我的代码:
import asyncio
import socketio
sio = socketio.Client()
@sio.event
def connect():
print("I'm connected!")
sio.emit('price_changed')
@sio.event
def connect_error(data):
print("The connection failed!")
@sio.event
def disconnect():
print("I'm disconnected!")
print('my sid is', sio.sid)
@sio.on('price_changed')
def on_message(data):
sio.emit(data)
print(data)
if __name__ == '__main__':
sio.connect('wss://www.haremaltin.com:2088')
sio.wait()
When I run python, I get output like this:
当我运行python时,我得到的输出如下:
enter image description here
在此处输入图像描述
The data I get is gold, euro, usd data.
我得到的数据是黄金、欧元、美元的数据。
I need want to assign each price to separate variable. Example:
我需要将每个价格分配给单独的变量。示例:
USD = USDprice
美元=美元价格
EUR = EURprice
欧元=欧元价格
How can i assign each price to separate variable?
我如何将每个价格分配给单独的变量?
更多回答
The response is json and you need to use a json parser/deserializer to get the data.
响应是json,您需要使用json解析器/反序列化程序来获取数据。
优秀答案推荐
You're getting JSON data back as a response. You're going to want to look into using the json
library in order to parse it, and then get what you will from it. When you parse it, it'll come in as a dict
so you just have to navigate that dictionary to pull the values out that you want.
您将得到作为响应的JSON数据。您将需要研究使用json库来解析它,然后从它获得您想要的东西。当您解析它时,它会以词典的形式出现,所以您只需浏览该词典就可以提取出您想要的值。
更多回答
我是一名优秀的程序员,十分优秀!