• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

python运行其他程序有哪些方法?

python 搞代码 4年前 (2022-01-09) 26次浏览 已收录 0个评论

python运行(调用)其他程序或脚本

在Python中可以方便地使用os模块运行其他的脚本或者程序,这样就可以在脚本中直接使用其他脚本,或者程序提供的功能,而不必再次编写实现该功能的代码。为了更好地控制运行的进程,可以使用win32process模块中的函数。如果想进一步控制进程,则可以使用ctype模块,直接调用kernel32.dll中的函数。

1 使用os.system函数运行其他程序
2 使用ShellExecute函数运行其他程序
3 使用CreateProcess函数运行其他程序
4 使用ctypes调用kernel32.dll中的函数

python运行其他程序的实现方法

这里提供了两种实现方法,一.os.system()函数和 使用ShellExecute函数运行其他程序及实现代码,大家可以参考下,

一 使用os.system()函数运行其他程序

打开系统的记事本程序

>>>import os>>> os.system('notepad')0>>> os.system('notepad python.txt')0

二 使用ShellExecute函数运行其他程序

>>>import win32api>>> win32api.ShellExecute(0,'open','notepad.exe','','',0)42>>> win32api.ShellExecute(0,'open','notepad.exe','','',1)42>>> win32api.ShellExecute(0<div style="color:transparent">本文来源gaodai.ma#com搞#代!码(网</div>,'open','notepad.exe','python.txt','',1)42>>> win32api.ShellExecute(0,'open','http://www.python.org','python.txt','',1)42>>> win32api.ShellExecute(0,'open','E:\\python\\work\\Demo.mp3','','',1)42>>> win32api.ShellExecute(0,'open','E:\\python\\work\\MessageBox.py','','',1)42

以上就是python运行其他程序有哪些方法?的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:python运行其他程序有哪些方法?

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址