亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

用Python實現命令行鬧鐘腳本實例

系統 1633 0

前言:

這篇文章給大家介紹了怎樣用python創建一個簡單的報警,它可以運行在命令行終端,它需要分鐘做為命令行參數,在這個分鐘后會打印”wake-up”消息,并響鈴報警,你可以用0分鐘來測試,它會立即執行,用揚聲器控制面板調整聲音。

以下是腳本:

            
# alarm_clock.py
 
# Description: A simple Python program to make the computer act 
# like an alarm clock. Start it running from the command line 
# with a command line argument specifying the duration in minutes 
# after which to sound the alarm. It will sleep for that long, 
# and then beep a few times. Use a duration of 0 to test the 
# alarm immediiately, e.g. for checking that the volume is okay.
 
# Author: Vasudev Ram - http://www.dancingbison.com
 
import sys
import string
from time import sleep
 
sa = sys.argv
lsa = len(sys.argv)
if lsa != 2:
  print "Usage: [ python ] alarm_clock.py duration_in_minutes"
  print "Example: [ python ] alarm_clock.py 10"
  print "Use a value of 0 minutes for testing the alarm immediately."
  print "Beeps a few times after the duration is over."
  print "Press Ctrl-C to terminate the alarm clock early."
  sys.exit(1)
 
try:
  minutes = int(sa[1])
except ValueError:
  print "Invalid numeric value (%s) for minutes" % sa[1]
  print "Should be an integer >= 0"
  sys.exit(1)
 
if minutes < 0:
  print "Invalid value for minutes, should be >= 0"
  sys.exit(1)
 
seconds = minutes * 60
 
if minutes == 1:
  unit_word = " minute"
else:
  unit_word = " minutes"
 
try:
  if minutes > 0:
    print "Sleeping for " + str(minutes) + unit_word
    sleep(seconds)
  print "Wake up"
  for i in range(5):
    print chr(7),
    sleep(1)
except KeyboardInterrupt:
  print "Interrupted by user"
  sys.exit(1)
 
# EOF
          

總結:

這個腳本我工作中已經在使用了,非常實用,當然為避免影響其他同事工作,你最好帶耳機,如果要求不高,其實從終端打印出的”wake-up”消息已經足夠提醒的了。以上就是這篇文章的全部內容,希望對大家的學習和工作能帶來一定的幫助,如果有疑問大家可以留言交流。謝謝大家對腳本之家的支持。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。?!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 色综合合久久天天给综看 | 韩日性视频 | 手机看片国产免费久久网 | 欧美精品网 | 国产高清在线精品一区二区 | 播放一级毛片 | 久久精品中文字幕久久 | 精品中文字幕在线观看 | 久久久精品波多野结衣 | 国产一区二区三区四区 | 欧洲老妇bbbbbxxxxx | 色综合久久久高清综合久久久 | 色91在线| 97干色| 久草视频在线观 | 国产欧美日韩精品一区二 | 国产高清在线a视频大全凹凸 | 国产精品久久久久久久久久妇女 | 曰本毛片va看到爽不卡 | 5x性区m免费毛片视频看看 | 亚洲欧美卡通成人制服动漫 | 精品中文字幕不卡在线视频 | 精产网红自拍在线 | 亚洲伊人久久大香线蕉结合 | 亚洲综合激情九月婷婷 | 福利姬在线播放 | 波多野吉衣一区二区三区四区 | 58av国产精品 | 精品国产一二三区 | 久久综合五月 | 午夜网站在线观看免费网址免费 | 久久精品入口麻豆 | 国产精品亚洲综合一区在线观看 | 国产a国产 | 亚洲一区二区三区日本久久九 | 五月开心婷婷 | 青青草久草视频 | 草莓视频一区二区精品 | 国产一区二区福利久久 | 久久亚洲精品一区二区三区浴池 | 欧美精品成人一区二区在线观看 |