尝试将字符串参数传递给函数,然后将其用作整个函数的变量。出于某种原因,当我尝试这样做时,它不起作用。我究竟做错了什么?
import subprocess
def printerSetup(printer):
subprocess.call(r'Cscript c:/windows/System32/Printing_Admin_Scripts/en-US/Prnport.vbs -a -r "'printer'.print.web.com" -h "' + printer + '.print.web.com" -o raw')
if printer == 'saturn' or printer == 'jupiter' or printer == 'neptune':
subprocess.call(r'rundll32 printui.dll, PrintUIEntry /if /b "' + printer + '" /f w:\printers\toshibae3511\eng\est_c2.inf /r "' + printer + '.print.web.com" /m "TOSHIBA e-STUDIO Color PS3"')
if printer == 'mercury':
subprocess.call(r'rundll32 printui.dll, PrintUIEntry /if /b "' + printer + '" /f w:\printers\dell1720\drivers\print\dell1720\DKABJ740.inf /r "' + printer + '.print.web.com" /m "Dell Laser Printer 1720dn"')
printerSetup("neptune")
printerSetup("mercury")
编辑了程序。在尝试运行这个新的之后,得到这个错误:
C:\Python27\Projects\Printer Setup>c:\python27\python.exe saturn.py
File "saturn.py", line 3
subprocess.call(r'Cscript c:/windows/System32/Printing_Admin_Scripts/en-US/P
rnport.vbs -a -r "'printer'.print.web.com" -h "' + printer + '.print.web.c
om" -o raw')
^
SyntaxError: invalid syntax