0

I've been programming in Python recently

I have 2 python file A.py and B.py

in B.py i have the following code

B.py

import A
import ...

async def main():
    cc = 'ethusdt'
    url = f'wss://stream.binance.com:9443/stream?streams={cc}@miniTicker'
    async with websockets.connect(url) as client:
        while True:
            data = json.loads(await client.recv())['data']

            event_time = time.localtime(data['E'] // 1000)
            event_time = f"{event_time.tm_hour}:{event_time.tm_min}:{event_time.tm_sec}"
            date_time = event_time
            price = float(data['c'])
            A.reciv_data(date_time,price))
            
if __name__ == "__main__":
    asyncio.run(main())

A.py


def reciv_data(a,b):
    x=a
    y=b 
    print(x)
    print(y)

Which constantly receives information from the server and prints it

I need B.py information in A.py so that when i run A.py first B.py start running and constantly receive information and in A.py give me to do those calculations Given that the data in B.py is constantly being updated, how can I have this data in A.py ? Thank you for your help

2
  • You can try writing data to a file or linux socket, or a normal socket Commented Jun 15, 2022 at 7:38
  • What data do you need to share between A.py and B.py? Can you add some more detail? I see B.py already imports A.py ... Commented Jun 15, 2022 at 7:52

1 Answer 1

0

If I understand you right - when you run A.py first, you want to actually get B.py up and running as that is the "starting point" of your data flow?

Suggest modifying A.py like so

def reciv_data(a,b):
    x=a
    y=b 
    print(x)
    print(y)

if __name__ == "__main__":
    subprocess.call('B.py', shell=True)

I don't think you need to worry about pipes etc here. But could be wrong on that.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.