Python 3 Récuperer dans une liste le nom des imprimantes

Fermé
xunil2003 Messages postés 761 Date d'inscription mercredi 17 novembre 2004 Statut Membre Dernière intervention 24 mars 2024 - Modifié le 9 févr. 2021 à 01:17
georges97 Messages postés 11947 Date d'inscription lundi 31 janvier 2011 Statut Contributeur Dernière intervention 28 mai 2024 - 9 févr. 2021 à 05:44
Bonjour,

Je suis sur python 3.6.9
J'ai besoin de récupérer dans une liste les noms des imprimantes

comme ceci :
laurent@Laurent-I7-9900K:~$ lpstat -s
system default destination: PDF
matériel pour Brother_MFC_9340CDW : ipp://BRN3C2AF4066966.local:631/ipp/print
matériel pour Brother_MFC_J5730DW : ipp://BRN3C2AF4C24E17.local:631/ipp/print
matériel pour MFC9340CDW : dnssd://Brother%20MFC-9340CDW._ipp._tcp.local/?uuid=e3248000-80ce-11db-8000-3c2af4066966
matériel pour OfficeJet-3830-series : hp:/usb/OfficeJet_3830_series?serial=CN8C16Q02B06VZ
matériel pour OfficeJet-3830-series-Fax-4 : hpfax:/usb/OfficeJet_3830_series?serial=CN8C16Q02B06VZ
matériel pour PDF : cups-pdf:/
laurent@Laurent-I7-9900K:~$


Mais ça ne fonctionne pas

def selectionner_imprimante():
print
print ("selectionner_imprimante")
print ("-----------------------")
LISTE_IMPRIMANTES = []
import os
import subprocess
CMD1 = "lpstat -s"
#cmd1 = os.popen(CMD1).read()
#cmd1 = subprocess.call(['lpstat', '-s'])
cmd1 = os.system(CMD1)

LISTE_IMPRIMANTES.append(cmd1)
print("LISTE_IMPRIMANTES : ",LISTE_IMPRIMANTES)


retour :
selectionner_imprimante
-----------------------
system default destination: PDF
matériel pour Brother_MFC_9340CDW : ipp://BRN3C2AF4066966.local:631/ipp/print
matériel pour Brother_MFC_J5730DW : ipp://BRN3C2AF4C24E17.local:631/ipp/print
matériel pour MFC9340CDW : dnssd://Brother%20MFC-9340CDW._ipp._tcp.local/?uuid=e3248000-80ce-11db-8000-3c2af4066966
matériel pour OfficeJet-3830-series : hp:/usb/OfficeJet_3830_series?serial=CN8C16Q02B06VZ
matériel pour OfficeJet-3830-series-Fax-4 : hpfax:/usb/OfficeJet_3830_series?serial=CN8C16Q02B06VZ
matériel pour PDF : cups-pdf:/
LISTE_IMPRIMANTES : [0]


Avec
cmd1 = os.system(CMD1)
et
cmd1 = subprocess.call(['lpstat', '-s'])
il liste les imprimantes mais impossible de les ajouter dans une liste ?

Merci d'avance pour vos conseils et avis.

Configuration: Linux / Firefox 85.0
A voir également:

1 réponse

xunil2003 Messages postés 761 Date d'inscription mercredi 17 novembre 2004 Statut Membre Dernière intervention 24 mars 2024 14
Modifié le 9 févr. 2021 à 03:08
Re,

J'ai trouvé il faut simplement l'écrire en dur.
cmd1 = os.popen("lpstat -s").read()


Retour :
LISTE_IMPRIMANTES :  [['system default destination: PDF\n', ' pour Brother_MFC_9340CDW : ipp://BRN3C2AF4066966.local:631/ipp/print\n', ' pour Brother_MFC_J5730DW : ipp://BRN3C2AF4C24E17.local:631/ipp/print\n', ' pour MFC9340CDW : dnssd://Brother%20MFC-9340CDW._ipp._tcp.local/?uuid=e3248000-80ce-11db-8000-3c2af4066966\n', ' pour OfficeJet-3830-series : hp:/usb/OfficeJet_3830_series?serial=CN8C16Q02B06VZ\n', ' pour OfficeJet-3830-series-Fax-4 : hpfax:/usb/OfficeJet_3830_series?serial=CN8C16Q02B06VZ\n', ' pour PDF : cups-pdf:/\n']]

Merci.
0
georges97 Messages postés 11947 Date d'inscription lundi 31 janvier 2011 Statut Contributeur Dernière intervention 28 mai 2024 2 274
9 févr. 2021 à 05:44
Bonjour,

Faux débutant python, je découvre vos scripts et vos références.

Merci pour le partage.
0