python可以采用交互式的()执行方式_Python一种在cons中实现交互式脚本执行的方法...

我正在为Django migrate/makemigrations命令开发一个web界面。我一直在检查代码,他们使用Python input()来获得{a1}的答案。在

目前,我尝试使用Python subprocess库,以便通过外部脚本(运行Python脚本的Python脚本)来回答问题。在

我生成了一个可以用作测试的简单脚本:

总和.pyfirst_number = input("Welcome to the program that sum two numbers, \

please give me the first number: ")

second_number = input("Now, please give me the second number: ")

print("Congratulations, the result of the sum of %s and %s is: %s" %

(first_number, second_number, (first_number + second_number)))

我发现让脚本运行第一个脚本的唯一方法是:

^{2}$

前几天我在网上发现了一些代码,可以让平安收到像实时的标准输出:from subprocess import Popen, PIPE

command = ["ping", "192.168.1.137"]

p = Popen(command, stdout=PIPE, stdin=PIPE, )

while p.poll() is None:

print p.stdout.readline()

我修改了代码并尝试运行脚本:

168.5字节=192.5字节/秒

从子流程导入Popen、PIPEcommand = ["python", "suma.py"]

p = Popen(command, stdout=PIPE, stdin=PIPE, )

response = "1\n"

while p.poll() is None:

print p.stdout.readline() #Obtain the message

p.stdin.write(response) #Answer the question

我找到了一些可能的方法节点.js像tty.js或{a3},但这可能很难理解,因为我对编程语言不太了解。在

我发现的是从stdout接收消息并将其发送到HTML页面,然后从用户那里获得响应。在

我有点不知所措,如有任何建议将不胜感激。

谢谢。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值