[英]How can i take the output of one python script as user input for another python script
[英]How can I send multiple “user input” to python script from another python script?
例如我有這個文件
#file2.py
while True:
name = input("Your name: ")
print("Hello ", name)
我想從其他 python 文件中運行 file2.py 並只發送輸入並獲取輸出。 我使用了子進程模塊以及標准輸入和標准輸出,但它在一次輸入后關閉了 file2.py,第二次輸入出現錯誤。
您可以使用import
。 將要從中打開 file2.py 的文件命名為 file.py 並在此處輸入您的代碼,在您希望打開 file2.py 的位置使用import file2
。 將文件保存在與 file2.py 相同的目錄中。 所以,file.py 應該是這樣的:
{code}
import file2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.