import win32api
import win32print
win32api.ShellExecute(0, "print", "test.txt", '/d:"%s"' % win32print.GetDefaultPrinter(), ".", 0)
如果txt打开的默认程序是记事本,可能会报下面的错;
查了很久没查到原因,后来试了doc文件可以打开,于是把txt默认打开程序换成了写字板就ok了
pywintypes.error: (31, 'ShellExecute', 'A device attached to the system is not functioning.')