我是靠谱客的博主 激情小霸王,最近开发中收集的这篇文章主要介绍windows python 双击运行_在windows中:双击运行Python,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

在windows中:双击运行Python程序、后台运行Python程序

一、安装Python解释器的windows环境,如果双击运行*.py的文件,会闪退。怎样避免闪退呢?

1、bat启动

start_show.bat  中

1python main.py

2、升级版:vbs后台运行(×××面)

start_hidden.vbs  中

12Set ws = CreateObject("Wscript.Shell")ws.run "cmd /c start_show.bat",0

二、windows中怎么快捷杀掉Python程序?

答:bat杀

stop_all_python.bat  中

1taskkill /IM python.exe /F

附录:

main.py 中

123456789101112131415161718192021222324252627282930313233343536import osimport loggingimport time # 如果日志文件夹不存在,则创建log_dir = "log"  # 日志存放文件夹名称log_path = os.getcwd() + os.sep + log_dirif not os.path.isdir(log_path):    os.makedirs(log_path) # 设置logginglogger = logging.getLogger()logger.setLevel(logging.DEBUG)main_log_handler = logging.FileHandler(    log_dir + "/dd_%s.log" % time.strftime("%Y-%m-%d_%H-%M-%S", time.localtime(time.time())), mode="w+",    encoding="utf-8")main_log_handler.setLevel(logging.DEBUG)formatter = logging.Formatter("%(asctime)s - %(filename)s[line:%(lineno)d] - %(levelname)s: %(message)s")main_log_handler.setFormatter(formatter)logger.addHandler(main_log_handler) # 控制台打印输出日志console = logging.StreamHandler()  # 定义一个StreamHandler,将INFO级别或更高的日志信息打印到标准错误,并将其添加到当前的日志处理对象console.setLevel(logging.INFO)  # 设置要打印日志的等级,低于这一等级,不会打印formatter = logging.Formatter("%(asctime)s - %(levelname)s: %(message)s")console.setFormatter(formatter)logging.getLogger('').addHandler(console) while True:    time_stamp = time.time()    # print("时间戳",time_stamp)    logger.info("时间戳 %s" % time_stamp)     sec = 3    logger.info("睡眠 %s 秒" % sec)    time.sleep(sec)

文件截图:

使用说明:

1、带界面双击启动

双击start_show.bat

会出现cmd窗口,同时会产生日志文件夹

2、不带界面后台运行程序

双击start_hidden.vbs

进程会增加一个python.exe进程,增加的python.exe进程为后台启动的,可以通过日志查看

3、杀死所有Python.exe进程

双击stop_all_python.bat

所有的Python进程都消失了,第1部中产生的cmd窗口也消失了。

最后

以上就是激情小霸王为你收集整理的windows python 双击运行_在windows中:双击运行Python的全部内容,希望文章能够帮你解决windows python 双击运行_在windows中:双击运行Python所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(56)

评论列表共有 0 条评论

立即
投稿
返回
顶部