参考网站:
https://stackoverflow.com/questions/510357/python-read-a-single-character-from-the-user
https://stackoverflow.com/questions/2988211/how-to-read-a-single-character-at-a-time-from-a-file-in-python
从stdin中逐字符读入:
1) sys.stdin.read(
从文件中逐字符读入:
= open('test.txt')
f = f.read(1) a
例子:
echo程序
从stdin读入:
import sys
if __name__ == '__main__':
= sys.stdin.read(1)
a while a:
print(a, end="")
= sys.stdin.read(1) a
从test.txt读入:
import sys
if __name__ == '__main__':
= open('test.txt')
f = f.read(1)
a while a:
print(a, end="")
= f.read(1) a