-2
尝试将一个字符串参数传递给一个函数,然后该函数将在整个函数中用作变量。出于某种原因,当我尝试这样做时,它不起作用。我究竟做错了什么?将一个字符串参数传递给一个函数 - 为什么它不工作?
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
请指定它不工作的方式。你是否试图将'printer'参数的值放入第一个'subprocess.call()'行的参数中? – unwind 2012-04-11 13:21:34
从什么意义上说它不起作用? – Marcin 2012-04-11 13:21:37
if语句后需要冒号。 – 2012-04-11 13:21:45