Windows自动执行python脚本操作步骤
作者:i see the future 时间:2023-04-22 15:32:42
上一篇自动在Windows中运行Python脚本并定时触发功能实现传送门链接
运行Python脚本:.bat文件
在Windows中,.bat文件是批处理文件,是与Linux中.sh(shell)文件很像的东西。
如果,我们想在Windows中运行一个Python脚本,我们可以通过CMD,首先进入python文件所在的目录,之后运行。
但是这样很麻烦,每次都要打开CMD,进入文件夹,运行文件。
所以,我们为了不每次都重复输入,建议把这些代码统一写在一个txt文件中,写完之后只要把txt文件的后缀改为.bat,然后双击运行就行啦。
cd C:\Users\Season\Desktop\
python timer.py
python脚本
import threading
import datetime
import time
def hello(RUNTIME):
print ("执行一次...")
global timer
timer = threading.Timer(RUNTIME, hello,[RUNTIME,])
timer.start()
if __name__ == "__main__":
print("now {}".format(datetime.datetime.now()))
year = int(time.strftime('%Y', time.localtime()))
month = int(time.strftime('%m', time.localtime()))
day = int(time.strftime('%d', time.localtime()))+1
hour = int(time.strftime('%H', time.localtime()))
minute = int(time.strftime('%M', time.localtime()))
myruntime = datetime.datetime(year,month,day,hour,minute,0)
RUNTIME = 24*60*60
print("{} 运行".format(myruntime))
timer = threading.Timer(RUNTIME, hello,[RUNTIME,])
timer.start()
bat运行经验
运行第一次失败,原因是路径中文无法识别
将路径更改为纯英文后,运行第二次成功。
提示:建议使用绝对路径,并且路径为纯英文。
定时在Windows中触发.bat文件
在Windows中,依照如下步骤触发作业:
1.右键单击“我的电脑”
2.选择“Manage/管理”,弹出如下窗口
3.依次选择System Tools/系统工具 - Task Scheduler/任务计划程序 - Task Scheduler Library/任务计划程序库
4.在右边Action一栏点击“Create Basic Task/创建一个基本任务”,创建一个基本任务
5.填写任务名称与描述,随便写就好了。单击下一步。
6.选择任务进行的频率与具体的时间
7.操作为启动程序
8.点击“Browse…”,选择我们想要运行的.bat文件
9.然后下一步,就Finish了。
10.返回“任务计划程序库”,查看你的任务。
来源:https://blog.csdn.net/m0_46629123/article/details/120070320
标签:Windows,自动执行,python
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Pycharm中的下载安装、配置与测试方式
2023-11-18 01:53:27
![](https://img.aspxhome.com/file/2023/2/101212_0s.png)
python的即时标记项目练习笔记
2022-11-25 05:49:35
![](https://img.aspxhome.com/file/2023/9/118499_0s.png)
使用绿色版SQLServer2008R2出现的问题解析
2024-01-22 23:42:58
![](https://img.aspxhome.com/file/2023/4/110944_0s.png)
select下拉菜单实现二级联动效果
2023-05-22 22:30:32
![](https://img.aspxhome.com/file/2023/1/135191_0s.gif)
Python中的协程(Coroutine)操作模块(greenlet、gevent)
2021-01-17 12:24:25
如何在python中用os模块实现批量移动文件
2022-07-08 20:36:40
js换图片效果可进行定时操作
2023-08-23 07:45:34
Python中搜索和替换文件中的文本的实现(四种)
2022-04-23 01:03:39
![](https://img.aspxhome.com/file/2023/7/111957_0s.png)
SQLSERVER查看数据库日志方法与语句示例代码(已亲测)
2024-01-17 21:32:35
![](https://img.aspxhome.com/file/2023/6/106236_0s.png)
交互设计实用指南系列(1) – “有效性”之“操作入口明确”
2009-12-11 18:42:00
![](https://img.aspxhome.com/file/UploadPic/200912/11/door-24s.png)
基于python的selenium两种文件上传操作实现详解
2022-01-31 23:02:17
![](https://img.aspxhome.com/file/2023/6/97666_0s.png)
Python NumPy教程之二元计算详解
2023-12-16 18:25:04
Python使用装饰器模拟用户登陆验证功能示例
2022-03-04 20:56:52
![](https://img.aspxhome.com/file/2023/7/114657_0s.png)
ASP:判断访问是否来自搜索引擎的函数
2008-03-12 11:39:00
Python 闭包,函数分隔作用域,nonlocal声明非局部变量操作示例
2023-07-29 00:03:51
win10下安装Go和Goland的详细教程
2024-02-12 10:57:16
![](https://img.aspxhome.com/file/2023/2/110522_0s.jpg)
手把手带你用python爬取小姐姐私房照
2022-04-09 16:02:04
![](https://img.aspxhome.com/file/2023/0/92320_0s.jpg)
配置php网页显示各种语法错误
2023-11-14 07:23:04
在vue.js中使用JSZip实现在前端解压文件的方法
2024-04-22 22:15:34
![](https://img.aspxhome.com/file/2023/9/136059_0s.jpg)
python进行两个表格对比的方法
2021-12-15 20:31:57