天天看點

Python運作外部程式的幾種方法

使用os.system函數運作其他程式或腳本

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

使用ShellExecute函數運作其他程式

ShellExecute(0, 'open', 'notepad.exe', 'python.txt', '', 1)
ShellExecute(0,'open','http://www.baidu.com','','',1)
ShellExecute(0,'open','F:\\Love\\Lady Antebellum - Need You Now.ape','','',1)
ShellExecute(0,'open','D:\Python\Code\Crawler\HanhanBlog.py','','',1)      

使用CreateProcess函數

import win32process
from win32process import CreateProcess
CreateProcess('c:\\windows\\notepad.exe', '', None, None, 0,
              win32process.CREATE_NO_WINDOW, None, None,
              win32process.STARTUPINFO())