Python 使用PyCups获取可用的打印机托盘
我正在尝试检索打印机的所有可用托盘,但找不到检索可用托盘列表的方法 这就是我获得打印机的方式:Python 使用PyCups获取可用的打印机托盘,python,macos,cups,Python,Macos,Cups,我正在尝试检索打印机的所有可用托盘,但找不到检索可用托盘列表的方法 这就是我获得打印机的方式: >>> import cups >>> conn = cups.Connection () >>> printers = conn.getPrinters () >>> for printer in printers: ... print printer, printers[printer]["device-uri"] B
>>> 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
它工作正常,但没有关于打印机中托盘的信息。非常感谢您的帮助或推荐
为了记录在案,我正在使用OS X。经过几次尝试之后,这里是我为获得托盘所做的工作
对于我找到的每台打印机,我都会查看/etc/cups/ppd/
中的Printer\u name.ppd
文件,在该文件中我可以找到我需要的所有详细信息
它也很有用,因为我可以获得PPDs文件中支持的每种语言的托盘。跟进已接受的答案:
由于PPD文件需要超级用户权限才能读取,因此使用PyCUPS访问它们的简单方法如下:
>>> import cups
>>> conn = cups.Connection()
>>> ppd = conn.getPPD('Brother_MFC_1910W_series') # Your desired printer's name
>>> print(ppd) # returns a filename of a temporary file with the PPD
'/tmp/576b35f2620f5'
>>> ppd_file = open(ppd)
>>> print(ppd_file.read())