writing to lpr printer

Alex Martelli alex at magenta.com
Wed Aug 9 05:05:02 EDT 2000


"Bob van der Poel" <bvdpoel at uniserve.com> wrote in message
news:3990BEDE.C1F4D417 at uniserve.com...
>
> In tcl I can do things like:
>
> open("|lpr", 'w')
>
> and tcl will open a pipe to lpr. The open in python doesn't behave this
> way...and I was very spoiled with the tcl varient. Is there an easy way
> to emulate this, or do I have to parse the filename looking for a
> leading '|', etc.?

_Somebody_ does have to do that parsing, but not necessarily 'you',
for some appropriate value of 'you'.  If you start every script with
    from mypy import *
then your package mypy.py has the opportunity to 'cover' any builtin
function's name whose behaviour you want to tweak with versions
that do what you desire.

http://www.seanet.com/~hgg9140/comp/pyperl-0.4/doc/index.html

provides a *LOT* of that -- in terms of emulation of perl idioms,
although it (wisely, IMHO) places them into a 'p' object, as its
methods, rather than using them to cover functions.  So, for
example, you can p.open("> $foo") to open-for-writing
the file whose name is in your variable named foo, and so on
perlingly.  I'm sure something quite similar could be concocted
for _Tcl_ idioms you're particularly fond of (the implicit $name
expansion is probably the single trickiest part of PyPerl).

Not saying or implying anything about the *wisdom* of so doing,
mind you, just about the *feasibility*.  You probably don't want
to just download and use PyPerl because the idioms it provides
are subtly (or grossly) different from the ones you're used to, e.g.
p.open("|goo.exe") and p.open("goo.exe|") with the position of
the | determining whether it's read or write, rather than a separate
"r" or "w" parameter, etc, etc.  But a PyTcl module based just
on those general ideas, not their specific  implementation, could
be what you desire.

As a personal suggestion, coming from a lot of Perl and not a
little Tcl, I *think* you'd be better off getting familiar with Python's
idioms rather than hankering for those you're used to.  Just
because you CAN imitate them doesn't mean you'll be happiest
by so doing -- just as people migrating from Pascal to C often
used to have lots of #define BEGIN {, #define END } and so
on, but mostly outgrew it pretty soon.  However, it's up to you!


Alex






More information about the Python-list mailing list