我知道这是可怕的编码。只是试图找出为什么我一直收到这个错误信息......
问题:什么时候没有提供脚本文件;为什么它会返回下面的错误而不是except块?否则,如果我在运行它时提供xml文件,脚本就可以工作。
回溯(最近一次呼叫最后):文件" C:\ bin \ read.py",第5行, 在 script,filename = argv ValueError:需要多于1个值才能解压缩
import sys
from xml.dom import minidom
from sys import argv
script, filename = argv
xmldoc = minidom.parse(filename)
total = len(sys.argv)
spacenumber = 1
space = "\t" * spacenumber
betweenspace = "\t" * 2
# ROOT ELEMENT <clusterConfig></clusterConfig>
rootElement = xmldoc.getElementsByTagName('clusterConfig')[0]
# CHILD ELEMENT 1 <instanceConfiguration></instanceConfiguration>
#childElement1s = rootElement.getElementsByTagName('instanceConfiguration')[0]
instanceRaters = rootElement.getElementsByTagName('instanceConfiguration')[0]
instanceUpdaters = rootElement.getElementsByTagName('instanceConfiguration')[1]
instanceGuiders = rootElement.getElementsByTagName('instanceConfiguration')[2]
instanceBulkLoaders = rootElement.getElementsByTagName('instanceConfiguration')[3]
instanceTaxers = rootElement.getElementsByTagName('instanceConfiguration')[4]
instanceDispatchers = rootElement.getElementsByTagName('instanceConfiguration')[5]
# CHILD ELEMENT 2 <configParameter />
#childElement2s = childElement1s.getElementsByTagName('configParameter')
raterAttributes = instanceRaters.getElementsByTagName('configParameter')
updaterAttributes = instanceUpdaters.getElementsByTagName('configParameter')
guiderAttributes = instanceGuiders.getElementsByTagName('configParameter')
bulkLoaderAttributes = instanceBulkLoaders.getElementsByTagName('configParameter')
taxerAttributes = instanceTaxers.getElementsByTagName('configParameter')
dispatcherAttributes = instanceDispatchers.getElementsByTagName('configParameter')
def runthis():
# Print rater configuration
print "RATER CONFIGURATION:\n"
for raterAttribute in raterAttributes:
print ("%s%s%s%s" %(space,raterAttribute.getAttribute('name'), betweenspace, raterAttribute.getAttribute('value')))
# Print updater configuration
print "\n\nUPDATER CONFIGURATION:\n"
for updaterAttribute in updaterAttributes:
print ("%s%s%s%s" %(space,updaterAttribute.getAttribute('name'), betweenspace, updaterAttribute.getAttribute('value')))
# Print guider configuration
print "\n\nGUIDER CONFIGURATION:\n"
for guiderAttribute in guiderAttributes:
print ("%s%s%s%s" %(space,guiderAttribute.getAttribute('name'), betweenspace, guiderAttribute.getAttribute('value')))
# Print bulkLoader configuration
print "\n\nBULKLOADER CONFIGURATION:\n"
for bulkLoaderAttribute in bulkLoaderAttributes:
print ("%s%s%s%s" %(space,bulkLoaderAttribute.getAttribute('name'), betweenspace, bulkLoaderAttribute.getAttribute('value')))
# Print taxer configuration
print "\n\nTAXER CONFIGURATION:\n"
for taxerAttribute in taxerAttributes:
print ("%s%s%s%s" %(space,taxerAttribute.getAttribute('name'), betweenspace, taxerAttribute.getAttribute('value')))
# Print dispatcher configuration
print "\n\nDISPATCHER CONFIGURATION:\n"
for dispatcherAttribute in dispatcherAttributes:
print ("%s%s%s%s" %(space,dispatcherAttribute.getAttribute('name'), betweenspace, dispatcherAttribute.getAttribute('value')))
try:
runthis()
except ValueError:
print "ERROR!!!! YOU FORGOT TO INCLUDE THE PARAMETERS.XML FILE!"
答案 0 :(得分:0)
根据我的理解,当你未能将足够的参数传递给ValueError: need more than 1 value to unpack
(参数变量)时,似乎会出现argv
。
例如,如果您通过命令行终端调用脚本,则需要键python script.py filename
。 (其中script.py
是脚本名称,filename
是您要分配给变量filename
的文件。)
如果只输入python script.py
,则会返回您描述的ValueError。这是因为通过使用argv
,您需要在调用脚本时输入变量。
希望这有帮助,请询问是否不清楚/这是否解决问题。