[Tutor] Something new in line printing?

Ken Green beachkidken at gmail.com
Mon Nov 11 19:55:58 EST 2019



On 11/11/19 7:13 PM, Alan Gauld via Tutor wrote:
> On 11/11/2019 22:51, Ken Green wrote:
>> I have not use Python printing for quite a while.
>> In the meantime, I acquired a new printer, a HP
>> OfficeJet 4652. Ran a program to print the output
>> of a program and get the following error:
> This is as much an OS problem as it is python so it helps
> if you start off by telling us which OS you are using.
> I assume some kind of Unix derivative but which?
>
>> lpr: Error - No default destination.
> This is an OS level error not a Python issue.
>
>> # sample_printing.py
>> # 11/11/2019
>>
>> import sys, os, time
>>
>> print
> This implies you are using Python 2.7?
> Might be worth considering a move to python 3 before support
> for v2 ends next year,.
>
>> datecode = "02042011"
>> month = datecode[0:2]
>> date?? = datecode[2:4]
>> year?? = datecode[4:8]
>> datecode = year + month + date
> Consider using the datetime module functions for date
> processing. But in this example slicing suffices I
> guess.
>
>> pr = (os.popen("lpr", "w"))
> os.popen is deprecated, the subprocess module is the recommended
> tool for this kind of task. It is much more powerful and flexible
> although somewhat more complex to use. But the module
> documentation gives several examples for most scenarios,
> including os.pipe.
>
>> pr.write (datecode)
>> pr.close()
> What happens here depends on your OS setup...
> Does it work outside python if you just cat a string into lpr?
>
>> Did something changed?
> Yes, your printer.
> Until we know that it is set up to work properly with lpr
> all bets are off.
I'm sorry to have forgotten to mention my OS and Python model.
I should have known better.

Currently using Ubuntu 18.04.3 LTS and Python 2.7.15+.  Been
using Ubuntu and Python2 before the new printer arrived in
spring of 2019 and no problem was noted before then. Usage of
printer other than Python2 was fine with current OS. I suppose
I should try using Python 3.6.8 and see what gives. Thanks.

Ken


More information about the Tutor mailing list