Printing
Craig Ringer
craig at postnewspapers.com.au
Tue Dec 21 22:44:54 EST 2004
On Wed, 2004-12-22 at 10:58, Jim & Joanne Collins wrote:
> I'm not using any widget or any graphics. I've done programs in Basic for
> years and they have all been strict data handling. I want to convert some
> to Python
> as Windows XP doesn't like 16 bit Basic.
Ah, I see. I thought you were using something like VB, because now when
many people say BASIC without further qualification they seem to mean
VB.
> If I have a line in basic that says "print "This is a test print"" how do I
> direct that line to the printer instead of the console? And to send an escape
> sequence with it for printer control in PCL what is the syntax/format required?
I don't have a windows box to test with - well, our NT4 server, but it
doesn't have anything on the serial ports. I would think that one just:
printerport = open("lpt1","w")
but on my NT box that results in a file not found exception. lpt0 opens,
but I have no idea if it works. I did a quick google search and turned
up little, but I'm sure this has been asked before so you might want to
try a google groups search, etc.
As for PCL commands - they're just part of the text stream, nothing
interesting or special about them at all. You just need to know how to
express them as Python string literals.
Untested: The sequence <esc>&d0D (begin underline) from my HP4MV manual
might be expressed as:
'\x1b&d0D'
or
'\x1b&d%iD' % 0
The %i substitutes in the argument specified after the string. Good for
escapes that can take many values. The \x1b is the escape sequence for
the 'escape' character, same as the ^[ code some MS-DOS editors use. In
most UNIX-like string escapes \e works too, but Python doesn't appear to
accept that.
IMO if you're doing much more than trivial formatting its much easier to
use PDF. I was lucky enough never to have to fight printers that viewed
output in terms of lines and columns, and I don't plan to start now ;-)
> How does one use the operating system after importing it? Syntax and
> commands?
help(os)
and see the Python documentation. Also note that 'import os' doesn't
import the operating system - it imports a Python module that provides
you with access to some operating system functionality.
> What is the syntax for using COM?
I'm afraid I have no idea - I don't use windows. The names win32all and
ctypes come up a lot here. You might want to check out the archives,
ctypes docs, ActivePython docs on win32all if any, etc.
Someone who uses COM on windows might want to give him a quick summary.
> In basic I write "shell"dir c:\temp\*.*>files.tem" and it does the same as
> a dir command
> at a DOS prompt and stores it in "files.tem" for me to access later.
You don't generally need to use temporary files like that in Python.
help(os.listdir) .
I strongly recommend you read the Python tutorial if you haven't
already, and have a browse over the documentation for some of the key
modules like os and sys. Google and Google Groups are also often very
helpful - you can use Google Groups to search comp.lang.python (this
list/newsgroup).
--
Craig Ringer
More information about the Python-list
mailing list