简体   繁体   English

在 Juypter 笔记本中的 function 中打印 function 不工作

[英]Print function not working inside a function in Juypter notebook

Print is not working in the execution is it is printing received message but not the message itself that is print(message) is showing no output in juypter notebook打印在执行中不起作用是它正在打印收到的消息,但不是打印(消息)的消息本身在 juypter 笔记本中显示没有 output

import websocket
import sys
from __future__ import print_function

SOCKET = "wss://stream.binance.com:9443/ws/ethusdt@kline_1m"
def on_open(ws):
    print('opened connection')

def on_close(ws):
    print('closed connection')

def on_message(ws, message):
    #global closes, in_position
    print('received message')
    json_message = json.loads(message)
    pprint.pprint(json_message)
    type(message)
    print(message)
    print('2222')
    candle = json_message['k']
    print(candle)
    is_candle_closed = candle['x']
    close = candle['c']

ws = websocket.WebSocketApp(SOCKET, on_open=on_open, on_close=on_close, on_message=on_message)
ws.run_forever()

The type of message you are getting is string.您收到的消息类型是字符串。 So you actually need to convert it into dictionary for jsoning.因此,您实际上需要将其转换为字典以进行 jsoning。 This is raising error.这是引发错误。
You can achieve this using eval() .您可以使用eval()来实现这一点。 But this is not at all a good practice.但这根本不是一个好习惯。
So, you first need to convert your message type from str to dict.因此,您首先需要将消息类型从 str 转换为 dict。 Then json it.然后json吧。 And everything will be fine一切都会好起来的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM