微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当我运行Python脚本时,为什么Win 7会发出哔哔声?

如何解决当我运行Python脚本时,为什么Win 7会发出哔哔声?

我看到了几个问题,问如何制作发出蜂鸣声的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 举报,一经查实,本站将立刻删除。