F
F
Feedok2021-08-04 17:51:02
Python
Feedok, 2021-08-04 17:51:02

How to get the text from the console through the code and enter the text that the console reads?

At the moment I am writing a program with Qt and Telethon libraries.
And when I log in to Telethon, it asks for a phone number to create a session and a confirmation code, while blocking the Qt window. You need to enter the number and code through the console. I had an idea to display a window through which you can enter a phone number and a code, but the question arises: how to enter something into the console through the code when it works for reading.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2021-08-04
@Vindicar

Run in a child process, intercept its standard input / output?
If you need inside your process, you can temporarily replace sys.stdin with something like io.BytesIO or io.StringIO filled with pre-prepared data. If you need to intercept stdout, then the contextlib module has such an opportunity.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question