Currently I am doing some tests with printers in Python, what I am trying to do is to list all the printers available.
Right now I am using PyCups library which exposes several useful APIs in the Connection
class. Among these there's also getPrinters()
:
Here's a snippet that I use and works:
>>> import cups
>>> conn = cups.Connection ()
>>> printers = conn.getPrinters ()
>>> for printer in printers:
... print printer, printers[printer]["device-uri"]
Brother_MFC_1910W_series
Photosmart_6520_series
I was wondering if there's any method to write the above code without using any external library. I am quite sure this can't be done without using C.
Any suggestion or reference to docs would be very appreciated. Thanks
I am using Python 3
It is possible to use C libraries from Python with standard modules only. References: CUPS API, ctypes. Translating CUPS structures and calls into
ctypes
syntax, we get a code that works under both standard OS X Python and Python 3:Be especially careful when using
ctypes
, most of errors would produce a segmentation fault.