S
S
s4q2020-07-26 05:50:42
Python
s4q, 2020-07-26 05:50:42

How to run the code and enter data?

There is a file, let's say test.py, as soon as you run it - immediately input, and you need to enter something. I need to run this file in another code and enter some text in the input. Is it possible?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilkhomjon Matazimov, 2020-07-26
@mr_qpdb

Is it possible?

Oh sure.
To do this, you need to create a file that will contain input.
For example, the file "test1.py" - which contains input.
You need to assign this input to a variable.
To do this, you can write the following code:
'''
Файл: test1.py
'''
text = input('Введите текст: ')

File 1 is already there, now in another code to run this input you need to create another file and import this input:
'''
Файл: test2.py
'''
from test1.py import text

Although this import will not be highlighted until you use it, it will still call input. Further, you can further exploit this input:
'''
Файл: test2.py
'''
from test1.py import text
print(text)  # Вывод содержимого

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question