gpt4 book ai didi

python - 值错误 : need more than 2 values to unpack in Python 2. 6.6

转载 作者:太空狗 更新时间:2023-10-29 16:54:06 25 4
gpt4 key购买 nike

我收到错误:ValueError:需要超过 2 个值才能解包当我现在运行单元测试时,有 2 次失败和 1 次跳过据我所知

lambda i: get_error_count(self._error_lookup, i))

line 142 of source is the method

for test, err, capt in errors:

which has the line of code:

count = get_error_count(i)

referencePython 3.0 has something a bit like this. Excess values can be bound(as a list) to the last variable:

a,b,*c = [1,2,3,4,5]

will result in c containing [3,4,5].

In Python 2.x, you can't do that directly, but you should be able tocreate a function that lengthens or shortens an input tuple of argumentsto the correct length so you can do:

a,c,b = fix(1,2)d,e,f = fix(1,2,3,4)

However, the function won't know the length of the left hand sidesequence, so it will have to be passed in as an extra parameter or hardcoded.

so the

count = get_error_count(i)uses only one variable, where asdef get_error_count(lookup, index):takes on 2

What should i use as the second variable ? to fix this ?

Thanks,-Kamal.

-------------------- >> begin captured stdout << ---------------------

\ test_many_errors.test_assert_one ... FAIL test_many_errors.test_one ... ok test_many_errors.test_assert_two ... ERROR test_many_errors.test_two ... ok test_many_errors.test_value_one ... ERROR test_many_errors.test_value_two ... SKIP: (, ValueError(), ) test_many_errors.test_good_one ... ok test_many_errors.test_good_two ... ok

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/Current/bin/nosetests", line 10, in <module>
sys.exit(run_exit())
File "/Library/Frameworks/Python.framework/Versions/6.3/lib/python2.6/site-packages/nose/core.py", line 117, in __init__
**extra_args)
File "/Library/Frameworks/Python.framework/Versions/6.3/lib/python2.6/unittest.py", line 817, in __init__
self.runTests()
File "/Library/Frameworks/Python.framework/Versions/6.3/lib/python2.6/site-packages/nose/core.py", line 196, in runTests
result = self.testRunner.run(self.test)
File "/Library/Frameworks/Python.framework/Versions/6.3/lib/python2.6/site-packages/nose/core.py", line 63, in run
result.printErrors()
File "/NOSE_TRIM/nosetrim-read-only/nosetrim/nosetrim.py", line 136, in printErrors
lambda i: get_error_count(self._error_lookup, i))
File "/NOSE_TRIM/nosetrim-read-only/nosetrim/nosetrim.py", line 142, in printErrorList
for test, err, capt in errors:
ValueError: need more than 2 values to unpack

/

-------------------->> 结束捕获的标准输出 << ------------------ ---


在 1.263 秒内运行 3 次测试

最佳答案

而不是在你的作业中解包:

a, b, c = do_something()

尝试将结果分配给单个变量并测试其长度:

t = do_something()
# t is now a tuple (or list, or whatever was returned) of results
if len(t) > 2:
# Can use the third result!
c = t[2]

关于python - 值错误 : need more than 2 values to unpack in Python 2. 6.6,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5515859/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com