#!/usr/bin/env python import os def sb_write(fd, servo, pulse): try: os.write(fd, '%d=%d\n' % (servo,pulse)) except IOError as e: print e try: fd = os.open('/dev/servoblaster', os.O_WRONLY) except OSError as e: print 'could not open /dev/servoblaster' raise SystemExit(5) except (KeyboardInterrupt, SystemExit): os.close(fd) pass