python - Windows 中 python 的 termios 模块是什么?
问题描述
首先,代码(我在这里找到:https ://github.com/defaultxr/taptempo.py/blob/master/taptempo.py )
#!/usr/bin/env python
from __future__ import print_function
import tty
import termios
from time import time
from sys import stdin
def getchar():
fd = stdin.fileno()
old_settings = termios.tcgetattr(fd)
try:
tty.setraw(stdin.fileno())
ch = stdin.read(1)
finally:
termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
return ch
def addtime(times):
if type(times) != list:
raise(TypeError)
t = time()
if len(times) == 0:
tdiff = 0 # initial seed
else:
tdiff = t - times[-1][0]
return (t, tdiff)
def averagetimes(times):
averagetime = sum([row[1] for row in times])/float(len(times))
bpm = (1.0/(averagetime/60.0))
return (averagetime, bpm)
def main():
print('Tap a key on each beat. Press q to quit.', end='\r')
times = []
while True:
char = getchar()
if char in ('q', 'Q', '\x1b', '\x03'): # q, Q, ESC, Control+C
print()
quit()
times.append(addtime(times))
if len(times) > 1:
# remove first element if it's either the initial seed
# or when the list reaches max length
if times[0][1] == 0 or len(times) > 16:
del times[0]
(averagetime, bpm) = averagetimes(times)
print("\rDetected BPM: %0.3f (Avg time between each: %0.3fs)"
% (bpm, averagetime), end='')
if __name__ == '__main__':
main()
我收到一条错误消息:“错误:找不到满足 termios 要求的版本错误:找不到 termios 的匹配发行版”
经过一番研究,事实证明,termios 是 Python 附带的,但它不包含在 Windows 发行版中(它只在 Linux 中),因为另一个名为“Airflow”的实用程序也不在 Windows 中。
我是一名音乐家,它看起来像是一个非常轻量级的小应用程序,非常适合“节奏敲击”。包含节奏敲击器的较大程序通常过于庞大且不必要,有时会有点慢。所以我只是想知道是否有办法让那个小应用程序在 Windows 中运行?
无论如何,这是一个有趣的问题。我从来没有在 Python 中遇到过 Windows 和 Linux 之间这样的“冲突”(如果可以这样称呼的话)。
解决方案
推荐阅读
- javascript - fabric.js 禁止在黑色像素上绘图
- swift - 在 swift 中使用数组从 FMDB 中删除数据
- json - 无法使用 ._find 提取价值
- python - for 循环中的 dict() - 不同的行为
- jsf - 如何根据列值更改 p:dataTable 中的行颜色
- javascript - 即使网页关闭,也可以在服务器上运行 JavaScript 应用程序
- microsoft-graph-api - 替换操作会破坏 OneNote 中的嵌套列表(图形 API)
- apache-spark-sql - Spark SQL 中的聚合函数列表
- angular - 来自回调的 Angular 6.x 显示值
- react-native - 调用 onEndReached 时 React Native (Redux) FlatList 跳转到列表顶部