[Tutor] Printing

Terry Carroll carroll at tjc.com
Tue Dec 27 09:55:37 CET 2005

On Mon, 26 Dec 2005, John Corry wrote:

> Thanks for the prompt reply.  This is exactly what I am looking for.
> However, I have tried the code on the page and I can't get it to work.
> Traceback (most recent call last):
>   File "c:\python24\jhc.py", line12, in ?
> 	0
> pywintypes.error: (2, 'ShellExecute', 'The system cannot find the file
> specified
> .')

Odd.  Works for me.

Just for the heck of it, try using a known filename, instead of making a 
randomly-named one, and try closing the file first:

import win32api
filename = "testprint.txt"
fileobj=open (filename, "w")
fileobj.write ("This is a test")
win32api.ShellExecute (

Then you can confirm at least, that your file is being created.

What version python are you using?  I'm using activestate's:

ActivePython 2.4.1 Build 245 (ActiveState Corp.) based on
Python 2.4.1 (#65, Mar 30 2005, 09:33:37) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

More information about the Tutor mailing list