python - 如何在 Python 中获取类似于 Pascal readkey 的字符

标签 python character pascal

在 Pascal 中,我可以执行此代码以从键盘输入中获取字符:

uses crt;
var ch: char;
begin
    ch := '.';
    while ch <> '\' do
    begin
        ch := readkey;
        writeln( ch );
    end;
end;

Python 中有类似的吗? :)

最佳答案

import sys    

def prog():    
    char = ""     
    while char != "/":    
        char = sys.stdin.read(1)    
        print char
prog()

关于python - 如何在 Python 中获取类似于 Pascal readkey 的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4799165/

相关文章:

python - 如何通过Selenium-Python访问 'rect'类型元素

c++ - 为什么我的数组没有输出正确的数据,这些数据是从外部文件输入的?

vba - VBA 中的哪个命令可以计算字符串变量中的字符数?

java - 在 switch 语句中使用 "default"case 是一个好习惯吗?

c++ - 帕斯卡到 C++ : trunc

Delphi 数组 : Variable Myvar might not been initialized

python - Python:Dictionary系列的Pandas数据框

python - 如何使用 SqlAlchemy 进行 upsert?

python pandas如何将不同数据框中的其他值乘以列

c - 当 gets(t) 从命令行获取输入 "Q"时,为什么 t != "Q"不终止 while 循环?