Can any one give me the cause of the above error message
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- 客户关系管理
- e-Commerce
- 会计
- 库存
- PoS
- Project
- MRP
此问题已终结
It is a Python exception that is the most ofen risen during assignation error: You try to do multiple assignment :
a, b = (1, 2, 3) # There is too many value to unpack ;)
a, b = (1, 2) # That will work
a, b = 'base.main_company'.split('.') # OK
a, b = 'base.main.company'.split('.') # KO
In OpenERP it generaly comes when there is a dot in an XML ID.
<record id='my.car' ...
You should not use the dot when creating an XML ID. It can also be risen when you try to acces an item by his XML id and pass wrong parameters.
That the most common cases but it may also come from any other piece of code...
Regards
Nicolas
Unpacking in Python:
- Imagine a function that returns multiple results, like a grocery list with several items.
- Unpacking allows you to assign each item on the list to a separate variable in your code.
- It's like taking things out of a bag one by one and putting them in designated spots.
The Error:
- The error pops up when you have more "spots" (variables) than items (returned values) or vice versa.
- If there are fewer variables than returned values, you're missing spots for some items, and Python doesn't know where to put them.
- On the other hand, if there are more variables than returned values, you have extra empty spots and not enough items to fill them all.
Python
def get_name_and_age():
return "Alice", 30 # Function returns a tuple with two values (name, age)
name, age, extra_variable = get_name_and_age() # Trying to unpack 3 values into 2 variables
https://slope3.io
In this example, the get_name_and_age function returns two values: "Alice" (name) and 30 (age). But the code tries to unpack these two values into three variables (name, age, and extra_variable). Since there's an extra variable, Python throws the "Too many values to unpack" error.
ValueError is a standard Exception raised by various methods that perform range-checking of some kind to signal that a value provided to the method fell outside the valid range. Python functions can return multiple variables . These variables can be stored in variables directly. This is a unique property of Python , other programming languages such as C++ or Java do not support this by default. The valueerror: too many values to unpack occurs during a multiple-assignment where you either don't have enough objects to assign to the variables or you have more objects to assign than variables.
More info: http://net-informations.com/python/err/value.htm
Another case may be regarding looping over dictionary. If one is looping on any dictionary with key and val both without using iteritems(), one will face this error:
a = {'test': 1, 'test 1': 2}
for k, v in a:
print k
It will give you that error but instead of one should use it like this:
a = {'test': 1, 'test 1': 2}
for k, v in a.iteritems():
print k
Still more information can be useful!
Thanks, Priyesh Solanki
相关帖文 | 回复 | 查看 | 活动 | |
---|---|---|---|---|
|
0
3月 25
|
399 | ||
|
0
12月 23
|
1405 | ||
|
5
2月 25
|
223751 | ||
|
1
12月 22
|
2333 | ||
|
2
11月 22
|
2363 |
Some context may help. Anyway, in python normally means you are trying to unpack a tuple with more values repect to target variables. Example: a,b = returnATupleOfMoreThan2Values()