• # une version python 2.7

    Posté par (site web personnel) . En réponse au journal Un tap tempo en ligne de commande. Évalué à 0.

    #!/usr/bin/python
    # -*- coding: utf-8 -*
    import sys,termios,tty,datetime
    def getKey():
     fd = sys.stdin.fileno()
     old_settings = termios.tcgetattr(fd)
     try:
     tty.setraw(fd)
     ch = sys.stdin.read(1)
     finally:
     termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
     return ch
    print "tapTempo : press any key (q for quit)"
    t=[]
    while getKey()!="q":
     t.append( datetime.datetime.now() )
    ll=[ (j-i).microseconds for i, j in zip(t[:-1], t[1:]) ][-5:]
    print "BPM:",60000000*len(ll)/sum(ll)