我之前就遇到过这个错误,原因很明显,但我在处理下面的代码片段时遇到了问题。
#!/usr/bin/python
ACL = 'group:troubleshooters:r,user:auto:rx,user:nrpe:r'
for e in ACL.split(','):
print 'e = "%s"' % e
print 'type during split = %s' % type(e.split(':'))
print 'value during split: %s' % e.split(':')
print 'number of elements: %d' % len(e.split(':'))
for (one, two, three) in e.split(':'):
print 'one = "%s", two = "%s"' % (one, two)
我添加了这些打印语句进行调试,并确认拆分正在生成一个 3 元素列表,但是当我尝试将其放入 3 个变量时,我得到:
e = "group:troubleshooters:r"
type during split = <type 'list'>
value during split: ['group', 'troubleshooters', 'r']
number of elements: 3
Traceback (most recent call last):
File "/tmp/python_split_test.py", line 10, in <module>
for (one, two, three) in e.split(':'):
ValueError: too many values to unpack
我缺少什么?