我正在使用一台装有Python的PC,通过与micro的串行连接来控制ASCII API。Python代码将命令作为键盘事件的结果发送到API。
我需要扩展input() --或者写一个新版本--“同时”监控串行连接。以这种方式,微串行连接上的进程可以发信号通知python代码并导致事件,其方式与PC上的键命令导致事件的方式相同。由于input()会在(string + \n)之前停止代码执行,因此需要扩展input()。
我有一个到微API的有效串行连接。
我不知道该怎么做。
我试过的东西都太难看了。
发布于 2019-11-05 03:35:29
您充其量也没有指定问题。但是,据我所知,您希望根据自己的喜好更改input ()函数。这样的事情是可以做到的,即使它代表了一个粗糙的解决方案。
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 4 20:16:13 2019
@author: Roberto Bellarosa
"""
import builtins
def fake_input(prompt):
print(prompt)
return "trgy"
builtins.input = fake_input
name = input("Enter your name >")
print("Hello,"+name+"!")https://stackoverflow.com/questions/58699570
复制相似问题