Re: Printing

Discussion in 'Python' started by Craig Ringer, Dec 22, 2004.

  1. Craig Ringer

    Craig Ringer Guest

    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
     
    Craig Ringer, Dec 22, 2004
    #1
    1. Advertising

  2. Craig Ringer

    Peter Hansen Guest

    Craig Ringer wrote:
    > 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.


    The above works, provided you have configured the printer
    to be addressable that way. Note that you might well want
    to use binary mode ("wb") to avoid newline-mangling.

    Python can open "lpt0", but that just creates a file with
    that name in your current directory... there is no such
    printer port.

    -Peter
     
    Peter Hansen, Dec 22, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon B
    Replies:
    7
    Views:
    7,614
    =?Utf-8?B?SmFzb25DaG9p?=
    Jan 30, 2006
  2. JustSomeGuy
    Replies:
    13
    Views:
    529
    msalters
    Dec 9, 2004
  3. iffy agbim
    Replies:
    1
    Views:
    132
    Mark Andrews
    May 24, 2004
  4. iffy agbim
    Replies:
    0
    Views:
    133
    iffy agbim
    May 21, 2004
Loading...

Share This Page