问题描述
我看到了几个问题,问如何制作发出蜂鸣声的Python脚本。
这个问题不是不是。
当我运行某些Python脚本时,Windows 7会发出蜂鸣声,但我想 停止蜂鸣 ..或至少了解其发生原因。
这是一个测试脚本-test.py:
#!/usr/bin/python
# importing modules
import os
import time
import datetime
from datetime import datetime
def f_log(strtext):
# In this method try and write to the log file
logFilePath = '/home/osmc/python/pyscripter_file.txt'
ts_local = datetime.Now()
ts = ts_local.strftime("%d/%b/%Y %H:%M:%s")
try:
# Check if the logfile exists
if(os.path.isfile(logFilePath)):
# Append the error message to the log file. 'a+' creates the file if it does not exist.
with open(logFilePath,'a+') as f:
f.write(ts + '\t' + strtext + '\n')
else:
print("Log File does not exist - Creating File Now")
with open(logFilePath,'a+') as f:
f.write(ts + '\t' + 'Log File does not exist - Creating File Now' + '\n')
f.write(ts + '\t' + strtext + '\n')
except IOError as e:
# Handle the exception
print("Error Msg")
f_log("Test Script")
print("Hello World")
此脚本位于运行OSMC的RaspBerry Pi上的目录中,位于/ home / osmc / python文件夹中 我已经在Pyscripter IDE中将其作为远程文件打开,可以看到ssh://osmc//home/osmc/python/test.py 因此,这意味着运行在Windows 7上的Pyscripter IDE正在远程计算机上运行Python脚本。当我以这种方式运行脚本时,执行完成后会发出蜂鸣声。
如果我创建了一个crontab以便在osmc中运行它...
PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/usr/bin/python
53 22 * * * /usr/bin/python /home/osmc/python/test.py >> out.txt 2>&1
然后脚本在执行结束时还会发出哔哔声。
如果我从命令行运行脚本到osmc(通过Putty中的ssh连接)
# cd /home/osmc/python
# python test.py
完成后,我没有发出哔哔声。
如果我在Pyscripter中运行此下一个脚本(或以任何其他方式),则不会发出哔声。
import sys
print('Python '+sys.version.replace('\n','')+' at '+sys.executable+' on '+sys.platform)
为什么有时会发出哔哔声?我猜第一个脚本中的Python代码中有东西吗?
Flex
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)