ETHEREUM WebSocket Data Send: Transfer data within class to def

As you in this article,

The question:

Suppose there is a class called “Myclass” whose methods manage website connections and send/receive data. When this can be caused by the way in which Python is treated.

Solution:

Argumas Methods methods. This way you can change the code:

`Python

Import weblocket

From the binance.client import client

Class MyClass:

Def __init __ (Self):

Self.data_to_send = no

Async De Handy_connection (Self, WebSocket):

Pass the data to send the reason for the shell

Self.data_to_send = "Hello from Myclass!"

Async def Handy_data_receed (Self, Data):

Print (F "taken: {Data}")

Async Def Main ():

Customer = Customer ()

Async with websockets.connect ("WSS: //api.binance.com: 9443") as a website:

my_class = myclass ()

Create an instance of myclass

Look forward to my_class.handle_connection (WebSocket)

Although true:

Data = Waiting for WebSocket.rekv ()

my_class.handle_data_reseced (Data)

Pass the data here to send

If __NAME__ == "__Main__":

Main ()

Explanation:

In the modified code when

The best exercise:

To avoid possible problems, for example:

`Python

Async def my_method (Self):

Self.send_data ("Hello from Myclass!")

Def Main ():

Customer = Customer ()

Async with websockets.connect ("WSS: //api.binance.com: 9443") as a website:

Wait my_method (website)

pass webSocket to the method

instead

my_class = myclass ()

Create an instance of myclass

Then call me directly

Data from a class with Binance API.

Rate this post

Để lại một bình luận

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *