2cme писал(а):Не работает, invalid syntax
В питоне очень важны отступы от левого края (indent), они как { } в си и php.
Вот это должно работать:
Код: Выделить всё
#!/usr/bin/env python
"""Copyright (C) 2009 Nick Drobchenko, nick@cnc-club.ru
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
work_thread = 0.05 # work_thread means how often pins will be updated (sec)
import os
import hal, time
h = hal.component("beep")
h.newpin("in", hal.HAL_BIT, hal.HAL_IN)
h.newpin("enable", hal.HAL_BIT, hal.HAL_IN)
# ok, lets we are ready, lets go
h.ready()
try :
while 1 :
time.sleep(work_thread)
if h["enable"] and h["beep"] :
os.exec("beep")
except KeyboardInterrupt :
raise SystemExit
ЗЫ Если пишет ошибку копируй ее целиком, там обычно есть еще куча полезной информации.