Ethereum: Passing data from within a class into def

Ethereum WebSocket Information Submit the problem: Data from class to def

When using the “binance.py” file, one of the mistakes you can face is to transmit data between classes and python functions. In this article, we discuss how to solve the problem when sending information through the Binance application connection with WebSockets.

Subject:

Suppose you have a “myclass” methods processing the webSocket Connections processing and sending/receiving information. When other classes or features call these methods, you may face a mistake to omit variables. This may be due .

Solution:

To solve the problem, you need to pass the variables as a keyword as -in -law when calling “Myclass” methods. So you can edit the code:

`Python

Bring in weblocket

Binance.client import customer

Class Mylass:

Def __init __ (yourself):

Self.data_to_send = no

Async Def Hands_connection (Self, WebSocket):

Ethereum: Passing data from within a class into def

Close the information to be sent here as Keywords Argument

Self.data_to_send = “Hello MyClassic!”

Async def foverne_data_receed (self, data):

Print (F “taken: {Data}”)

Async Def Main ():

Customer = Customer ()

Async withkets.connect (“WSS: //api.binance.com: 9443”) WebSocket:

my_class = myclass ()

to create myclass

Wait my_class.handle_connection (WebSocket)

Although true:

Data = Wait WebSocket.rekv ()

my_class.handle_data_received (data)

decide this

If __NIMI__ == “__Main__”:

Main ()

`

Explanation:

In the edited code, we create the Main () function “Myclass” example and call it directly. When you try to transfer variables between classes or features, without a keyword, Python awakens “TypeError”. If you transmit the variables as keywords (Self.data_to_send =" Hello Myclassic! " `), You can send information between the classes.

The best exercises:

To avoid changing sections, consider using activities and class methods instead of expression properties. For example:

Python

Async def my_method (Self):

Self.send_data (“Hello myclassic!”)

Def Main ():

Customer = Customer ()

Async withkets.connect (“WSS: //api.binance.com: 9443”) WebSocket:

Wait My_Method (WebSocket)

Motion to WebSocket Method

instead

my_class = myclass ()

to create myclass

Then call processing and handy_data_receed methods directly

`

In keeping with these steps, you must be able to solve the problem when transferring information within the class to “Def” when using WebSocks using Binance.

ethereum python specific

Leave a Reply

Your email address will not be published. Required fields are marked *