[Tutor] Printing

bob bgailer at alum.rpi.edu
Wed Dec 28 01:47:36 CET 2005


At 08:52 AM 12/26/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.
>
>import tempfile
>import win32api
>
>filename = tempfile.mktemp (".txt")
>open (filename, "w").write ("This is a test")
>win32api.ShellExecute (
>   0,
>   "print",
>   filename,
>   None,
>   ".",
>   0
>)

Also beware that the file must have an extension associated with an 
application that recognizes the print command. e.g. if the file is 
named foo.doc and .doc is registered as belonging to MS Word, then 
this will open MSword, open the file, print the file and close Word. 
It is the equivalent of right-clicking the file in the explorer and 
then choosing Print from the context menu.


>I am using the Pythoncard code editor and I get the following error:
>
>Traceback (most recent call last):
>   File "c:\python24\jhc.py", line12, in ?
>         0
>pywintypes.error: (2, 'ShellExecute', 'The system cannot find the file
>specified
>.')
>
>I have played about with it and saved it in various places but I can't get
>it to work.  Any suggestions?  Do I need to import other modules?  Do I need
>to use Pythonwin?
>
>Thanks,
>
>John.
>
>-----Original Message-----
>From: tutor-bounces+john.corry=ntlworld.com at python.org
>[mailto:tutor-bounces+john.corry=ntlworld.com at python.org]On Behalf Of
>Danny Yoo
>Sent: 24 December 2005 19:33
>To: John Corry
>Cc: Tutor
>Subject: Re: [Tutor] Printing
>
>
>
>
> > I have downloaded win32, win32com, Preppy and PIL.  I have had a go at
> > using them but can't get them to work.  At the moment I can't even print
> > the text file.
> >
> > Is there a good helpguide/FAQ page which deals with printing text files
> > or is there simple code which prints a text file?
>
>Hi John,
>
>
>Let's see... ok, found it!  Tim Golden has written a small introduction to
>printing:
>
>     http://tgolden.sc.sabren.com/python/win32_how_do_i/print.html
>
>His recommendation is to use the ShellExecute function in win32api to send
>off documents to your printer.
>
>
>
>Best of wishes!
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list